# vectors in a vector

This topic is 4873 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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

##### Share on other sites
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.

##### Share on other sites
Another solution is a vector of pointers to vectors of pointers to objects. One reasons is object reconstruction.

Kuphryn

##### Share on other sites
Quote:
 Original post by kuphrynAnother 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++.

##### Share on other sites
Quote:
Original post by snk_kid
Quote:
 Original post by kuphrynAnother 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.

• 11
• 20
• 12
• 9
• 34
• ### Forum Statistics

• Total Topics
631399
• Total Posts
2999846
×