Coder's Guild Mailing List

C++ questions

Posted by Weasel on 1999-05-24

Ok, what's the difference between those two methods:

    CGrowing_Grid growing_grid;
    growing_grid.set_occupied(0,0,0);


and

      CGrowing_Grid *growing_grid;
      growing_grid = new CGrowing_Grid;

      growing_grid->set_occupied(0,0,0);

      delete growing_grid ;

????????????????


Ok, I know I'm making a pointer in the second type and aligning its
memory at runtime, but I don't know why the first version ALWAYS
SEGFAULTs while the second seems to work without problems.

PS: CGrowing_Grid is a class with a constructor called CGrowing_Grid()
and also has an (empty) destructor ~CGrowing_Grid().

any help?


and second:
is there a way to do the following faster (it seems to take hours):

    for (int x=0; x<CUBE_SIZE; x++)
    for (int y=0; y<CUBE_SIZE; y++)
        for (int z=0; z<CUBE_SIZE; z++)
        {
            for (int i=0; i<NR_OF_SUBSTANCES; i++)
            grid[x][y][z].concentration[i] = 0.0;
            
            grid[x][y][z].occupied = false;
        };

with

struct TGrowing_Gridcell{
    float concentration[NR_OF_SUBSTANCES];
    bool occupied;
};

and
    TGrowing_Gridcell grid[CUBE_SIZE][CUBE_SIZE][CUBE_SIZE];

PS: CUBE_SIZE is large (first I wanted to have it 256 but calculate the
RAM needed :), now its either 64 or 128, don't know yet)
NUMBER_OF_SUBSTANCES is 16



TIA

-- 
Weasel                          mailto:palfrader@xxxxxxx.xxx
Peter                   http://www.cosy.sbg.ac.at/~ppalfrad/
------------------------------------------------------------
     We have full klingon console support just in case.
                         -- Alan Cox on linux-kernel