From: sparhawk AT eunet DOT at (Gerhard Gruber) Newsgroups: comp.os.msdos.djgpp Subject: Re: Allocation (malloc) Date: Tue, 30 Jun 1998 19:04:39 GMT Organization: Customer of EUnet Austria Lines: 67 Message-ID: <359f2e98.3655664@news.Austria.EU.net> References: NNTP-Posting-Host: e162.dynamic.vienna.at.eu.net Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Destination: Federico Spinazzi From: Gruber Gerhard Group: comp.os.msdos.djgpp Date: Tue, 30 Jun 1998 17:02:41 +0200 (MET DST): >I think >here you are declaring pointer to a 2-dimensional array. Why not to use I suppose you never tested that code? >#include >#include > >int main() >{ > >int **vertice, count, allocated; > >/* >Maybe you know that you need a 10-element array. However: >*/ > >vertice = (int **)malloc(sizeof(int *); ) missing >if (vertice == NULL) > { cprintf("Not enough memory"); exit(0); } > >for (allocated = 1, count = 0; count<10; count++) > { > vertice[count] = (int *)malloc(HOW_MANY_I_NEED); I suggest using malloc(HOW_MANY... * sizeof(int)) instead. >You should be able to read and write in vertice[][]. > BUT, why MSS complain thet I have corrupted memory calling Because if you reference the memory this way you would need one single chunk of memory that is big enough for the array. assuming int m[10][10]; you need to allocate a block of 100 ints assigned to m. Your above code doesn't do this because you'd allocate 10 pointers! to ints. But that doesn't work either because the compiler needs to know how big the array is in order to calculate the indizes when you access the array. >free(vertice) ? > >Is it a correct waring o a bug in it? It is correct. >I've written to MSS writers but they are too busy ... :)))) What did you expect? :) >I'm right or not ?. You are right. they really are to busy. :) SCNR. -- Bye, Gerhard email: sparhawk AT eunet DOT at g DOT gruber AT sis DOT co DOT at Spelling corrections are appreciated.