vector data size in bytes

Hello forum,

I have a functional application that declares an array as follows:

1
2
3
4
glm::vec3 vertices[(NUM_X+1)*(NUM_Z+1)];
......................

glBufferData (GL_ARRAY_BUFFER, sizeof(vertices), &vertices[0], GL_STATIC_DRAW);


Just check the part sizeof(vertices)

I am re-engineering it and using the std vectors instead as follows:

1
2
3
std::vector<glm::vec3> mVertices;
mVertices.resize((NUM_X+1)*(NUM_Z+1));


Now how to find the size of the mVeritces in bytes ?
Now how to find the size of the mVeritces in bytes ?
Amount of elements (mVeritces.size()) multiplied by size of one element:
1
2
3
4
//Either
sizeof(mVertices[0])
sizeof(decltype(mVertices)::value_type)
sizeof(std::vector<glm::vec3>::value_type)
I think I don't want to know the size of the vector in bytes, because the vector is a non-trivial object.

What I probably want to know is the size of the data, the number of bytes required to store the current contents of the vector. Should the following a valid one ?

 
sizeof(glm::vec3) * mVertices.size()
Yes. This is amount of data stored in vector in bytes.
Topic archived. No new replies allowed.