Dynamic multi-dimensional arrays
Is there an easy way to create a dynamically-allocated multi-dimensional array? The following is the way I am creating it at the moment, but there''s surely a faster (and more readable) method! Here I''m creating a vertices[9][3] array. For example, it could hold nine x,y,z vertices...
int number = 9;
float** vertices;
vertices = (float**)malloc(sizeof(float*)*number);
for( int i = 0 ; i < number ; ++i)
{
vertices = (float*)malloc(sizeof(float)*3);
}
Thanks,
MadCow(an)
April 06, 2001 02:10 PM
Depending on your data type you could use a valarray.
Or a mulitdimensional vector.
Or a mulitdimensional vector.
Are you using just C? If you''re using C++ you could do:
float (*p)[3] = new float[9][3];
Not sure how you could do it in C, sorry.
Still, in C or C++, I''d use a struct instead.
struct Vertex
{
float x, y, z;
};
Vertex *vertexarray = new Vertex[9];
Jesse Chounard
float (*p)[3] = new float[9][3];
Not sure how you could do it in C, sorry.
Still, in C or C++, I''d use a struct instead.
struct Vertex
{
float x, y, z;
};
Vertex *vertexarray = new Vertex[9];
Jesse Chounard
Website - Third Party Ninjas | Twitter - twitter.com/Chounard
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement