Sign in to follow this  
CRACK123

vectors in a vector

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 this post


Link to post
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 this post


Link to post
Share on other sites
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++.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this