Mail Archives: djgpp/1997/04/04/09:45:22
William Heymann <heymann AT ucsu DOT Colorado DOT edu> 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
- Raw text -