delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/07/11/12:45:45

From: Endlisnis <s257m AT unb DOT ca>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Dynamic Arrays and C++
Date: Fri, 10 Jul 1998 11:12:55 -0300
Organization: University of New Brunswick
Lines: 23
Message-ID: <Pine.SOL.3.96.980710110905.12175A-100000@sol.sun.csd.unb.ca>
References: <AEA709B50D3807D4 DOT DBB9E9D19B2BCC95 DOT 9840599F888D1195 AT library-proxy DOT airnews DOT net> <6o0ck8$hs0$1 AT news DOT bctel DOT net> <Pine DOT SOL DOT 3 DOT 96 DOT 980708171954 DOT 3501C-100000 AT sol DOT sun DOT csd DOT unb DOT ca> <35A5658B DOT 4E09 AT sentex DOT net>
NNTP-Posting-Host: sol-alt1.unb.ca
Mime-Version: 1.0
In-Reply-To: <35A5658B.4E09@sentex.net>
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

On Thu, 9 Jul 1998, temujin wrote:
->> You could say:
->> int* test = new int[64];
->> And then use test[x*8+y] to resolve test[x][y].
->> Or, if the dimensions are constants, don't dynamically allocate.
->If you *MUST* use dynamic arrays and want to do it with
->OBJECTS/structures you have to remember to  
->WHATEVER **myarray=malloc......
->Have to have the double pointer thing to make it an array of pointers
->which point to objects.  With just   *myarray you create an array of
->unique and seperate objects.
        But, if you do it that way, you then have to go through the loop
and allocate memory (with new or malloc) for each pointer:

char** a = new (char*)[8];
for(int c=0; c<8; c++) a[c] = new char;

	That's alot more fuss (and requires memory for allocation overhead
than just allocating one 64 char block and treating it like a 2d array.

	Endlisnis
[I have a pyramid of wingyness]

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019