
help please: problems with arrays
yikes! you could do this more efficiently with a nested union inside of your
struct. Go read up on it you will see what I am talking about. As for the
memory allocation and deallocation, you would want to create a new object of
the struct, then when you are finished with the object call the delete on
the struct. You could also make a class out of it.
Steven
Quote:
> I am using Visual C++ and I am having trouble with this bit of code which
is
> unfortunately the core of my program in a way.
> I don't know how to allocate memery properly and how to free the memory at
> the end of each loop
> // Here are my structures
> typedef struct vertex
> {
> float coords[3];
> } vertex;
> typedef struct triangle
> {
> int i[3];
> int adj[3];
> int angle[3];
> vertex *verts[3];
> vertex *normal;
> float creaseangle;
> } triangle;
> // Here is my array of structure
> triangle T[MAX_SHAPES][MAX_TRIS];
> As you can see I've got an array of structure...
> I have a loop which fills this array with values... I would like to
allocate
> memory and free memory because once I want to use the function another
> time... the values in the array are very strange
> here is an axample of my function:
> void Cmyclass::fill_array()
> {
> for (int x=0; x<maxshapes; x++)
> {
> for (int y=0; y<maxtriangles; y++)
> {
> T[x][y].verts->coords[0] = data[0];
> T[x][y].verts->coords[0] = data[1];
> T[x][y].verts->coords[0] = data[2];
> }
> }
> }
> Thanks a lot!!!
> Nicolas Bussard