vectors in a vector

Started by
3 comments, last by CRACK123 19 years, 2 months ago
Hi, I am thinking of having a vector within a structure. Now again this structure will be a vector. Is it possible to have a such a thing ? I currently have the structure like this :-
[Source]
typedef struct
{
    // batch the model on a per material basis
    MaterialInfo material;
    vector3 *normals;
    int *faces;
    int numFaces;
    NodeInfo *info;
    
} VBOStruct;
[/Source]
Now I plan to make it like the following
[Source]
typedef struct
{
    // batch the model on a per material basis
    MaterialInfo material;
    vector<vector3> normals;
    vector3 <int> faces;
    int numFaces;
} VBOStruct;
[/Source]
Now I am initializing the VBOStruct like the following : vector <VBOStruct> vbo; Now is this feasible and if it is how would I copy the info into the VBOStruct, would a regular push_back work fine or I should go back the c type linked list ? Thanks
The more applications I write, more I find out how less I know
Advertisement
Quote:Now is this feasible

Yes.

Quote:and if it is how would I copy the info into the VBOStruct, would a regular push_back work fine

Yes.

Depending on the way you're going to use it, you may want to pick a different container than vector <VBOStruct> vbo;, but if it only gets filled when you start the application, you should be fine.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Another solution is a vector of pointers to vectors of pointers to objects. One reasons is object reconstruction.

Kuphryn
Quote:Original post by kuphryn
Another solution is a vector of pointers to vectors of pointers to objects. One reasons is object reconstruction.


That is unnecessary and a std::vector of pointers to 3 element Vector is not as efficent as holding the 3 element Vectors themselfs, besides if you know what your doing you would look-up and/or use a std::vector::reserve, you would do simillar for std::vector of VBOStruct.

@CRACK123

lose the typedef'ing your structures, its redundant in C++.
Quote:Original post by snk_kid
Quote:Original post by kuphryn
Another solution is a vector of pointers to vectors of pointers to objects. One reasons is object reconstruction.


That is unnecessary and a std::vector of pointers to 3 element Vector is not as efficent as holding the 3 element Vectors themselfs, besides if you know what your doing you would look-up and/or use a std::vector::reserve, you would do simillar for std::vector of VBOStruct.

@CRACK123

lose the typedef'ing your structures, its redundant in C++.


I dont get it. Are you implying that I hold a face info rather than a single vector ? The whole idea is to batch the info on a per material basis so that I can send a set of info to glDrawElements, hence I need 1 vector as compared to 3 vectors at a time. And besides I dont intend to hold any vertex information in this structure, just index elements. Vertices are held totally outside this structure.

The more applications I write, more I find out how less I know

This topic is closed to new replies.

Advertisement