Coder's Guild Mailing List

Re: C++ Questions

Posted by Dan Nuffer on 1999-05-25

> struct TGrowing_Gridcell{
>     float concentration[NR_OF_SUBSTANCES];
>     bool occupied;
> };
>
> CGrowing_Grid {
> ..
> TGrowing_Gridcell grid[CUBE_SIZE][CUBE_SIZE][CUBE_SIZE];
> ..
> }
<snip>
> do I also allocate mem for the array concentration[] or just for the
> pointer to an array??
>

Yes, you do get the whole concentration array allocated CUBE_SIZE^3 times.
One thing you could consider doing is to use a sparse array.  This depends
on your application, but if most of the CGrowing_Grid doesn't change, you
can just keep a hash table of the items that aren't the default value.  This
would also get rid of all the time it takes to initialize the array.

Dan Nuffer