delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/08/18/12:15:41

From: Erik Max Francis <max AT alcyone DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: positive ints and arrays
Date: Tue, 18 Aug 1998 08:59:56 -0700
Organization: Alcyone Systems
Lines: 21
Message-ID: <35D9A4FC.1709C5CA@alcyone.com>
References: <199808161131 DOT NAA08483 AT d1o22 DOT telia DOT com> <35D86D67 DOT FC0683E0 AT unb DOT ca>
NNTP-Posting-Host: charmaine.alcyone.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Endlisnis wrote:

> If you need more than one dimension to be
> dynamic, then you have to 'fake-it'.  If you want something NxM, then:
> char* Array = new /* or malloc */ [N*M];
> Array[X*N+Y];  //To access Array[X][Y].

Not true.  You can first allocate a array of pointers to the data type,
and then for each element of the array allocate arrays of the data type
and assign it to that index.  That gives you a fully-dynamic two
dimensional array, but in addition requires N + 1 pointers and N + 1
allocations.

-- 
Erik Max Francis / email max AT alcyone DOT com / whois mf303 / icq 16063900 
Alcyone Systems / irc maxxon (efnet) / finger max AT sade DOT alcyone DOT com
  San Jose, CA / languages En, Eo / web http://www.alcyone.com/max/
          USA / icbm 37 20 07 N 121 53 38 W / &tSftDotIotE
             \
            / Shooters, looters; now I got a laptop computer
           / Ice Cube

- Raw text -


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