Message-Id: Comments: Authenticated sender is From: "Salvador Eduardo Tropea (SET)" Organization: INTI To: heymann AT ucsu DOT Colorado DOT edu, djgpp AT delorie DOT com Date: Fri, 4 Apr 1997 11:40:33 +0000 MIME-Version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Subject: Re: Dynamic Allocation of Multidimensional Arrays William Heymann wrote: > So how do I make a dynamic two dimensional array in C++? What about using malloc and calculating the offset similar to how you calculate coordinates in the screen? For example if you need an array of 320x200 ints: int *array; array=(int *)malloc(320*200*sizeof(int)); ..... suppose that X and Y are the index values ... array[X+Y*320]=n; Of course 320 and 200 can be variables, and ofcourse isn't too fast because the product can't be optimized if you use a variable. If you can determine the maximun "X" of the array perhaps you can allocate ever this width and only change the height, so the product is constant, for example maximun X is 1024, you'll have: array[X+Y*1024] Where 1024 is a constant and will be optimized as a shift. SET --------------- 0 -------------------------------- Salvador Eduardo Tropea (SET). Address: Curapaligue 2124, Caseros, 3 de Febrero Buenos Aires, (1678), ARGENTINA TE: +(541) 759 0013