vector data size in bytes
Feb 8, 2015 at 9:39am UTC
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 ?
Feb 8, 2015 at 9:50am UTC
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)
Feb 8, 2015 at 10:10am UTC
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()
Feb 8, 2015 at 10:21am UTC
Yes. This is amount of data stored in vector in bytes.
Topic archived. No new replies allowed.