Original Post
I would like to allocate some fixed amount of memory to vector.
I have the following structure:
Some declaration in code:
And then I try to alloc memory this way:
The problem is that my progam crashes when application tries to access some field of nodes[0]. In fact, size() of the vector indicates to 0 after memory reservation. I am almost sure that yeasterday this stuff worked and today it doesn't. Moreover, in some other places I also do forward allocation this way and it works.
Does anyone know what might be the problem?
NOTE:
Such allocation:
works but this is now what I want to do every time I need forward allocation - raw C arrays are much neater in this situation!
I have the following structure:
struct MeshNode{ mtx normalTransform; int verticesNum; int texCoordsNum; vector<vec3> vertices; vector<vec2> texCoords; vector<NodeFace> faces; vector<vec3> verticesNormals; vector<vec3> facesNormals;};Some declaration in code:
vector<MeshNode> nodes;And then I try to alloc memory this way:
nodes.reserve(this->nodesNum);The problem is that my progam crashes when application tries to access some field of nodes[0]. In fact, size() of the vector indicates to 0 after memory reservation. I am almost sure that yeasterday this stuff worked and today it doesn't. Moreover, in some other places I also do forward allocation this way and it works.
Does anyone know what might be the problem?
NOTE:
Such allocation:
for (unsigned int i = 0; i < this->nodesNum; i++) { MeshNode meshNode; nodes.push_back(meshNode); }works but this is now what I want to do every time I need forward allocation - raw C arrays are much neater in this situation!