I'm trying to effectively make a dynamically resizable array of pointers. But I think i'm being silly.
My problem is i'm not sure how to write it out.
typedef struct
{
double x,y,z;
} Vertex3D;
typedef struct
{
Vertex3D *v0;
Vertex3D *v1;
Vertex3D *v2;
unsigned int color;
float alpha;
bool use_alpha;
} TTriangle;
class mesh
{
public:
mesh();
~mesh();
void addVertex( Vertex3D *Vertex );
private:
};
these are my basic structures. What I want to do is define an empty variable thats a pointer to an array of pointers. then, as I add verticies, I want to create a new array of pointers, copy the old pointers into the new array, add the new pointer to the end, delete the old array then update the array pointer to point to the new array of pointers.
The array of pointers would point to different verticies. So something along the lines of: -
int *VerticiesArrayPointer; // pointers to arrays are ints?
vertexCount++;
int *Verticies[vertexCount] = malloc(sizof(int)*vertexCount); // I dont know how to do this?
copy &VerticiesArrayPointer to Verticies; // copy old array of pointers to new array of pointers
delete *VerticiesArrayPointer; // free old array of pointers memory
Verticies[vertexCount] = *newVertex; // add the new Vertex3D pointer to the end of the new array of pointers
*VerticiesArrayPointer = *Verticies; // set the pointer to the array to the new array
but I dont know how to do any of the above, or even what to search for on how to do it. I dont even know if thats just dumb :S
The reason I want to do it this way is because I dont know how big the array of verticies is going to be. Should I scrap this idea and just create a large array and not worry about memory usage?
Thnx for any help or direction.



