I'm creating objects at runtime with vector.push_back() and i want to store the player object so i can use it whenever i want. So i store the pointer of the just created player to a global pointer variable, but when i push back the next object, the memory adress of the player changes, i think because the vector has to resize and therefore changes all of its elements locations.
for (int y = 0; y < 5; y++)
{
for (int x = 0; x < 10; x++)
{
switch (map[x + 10 * y])
{
case '1':
gameObjects.push_back(player);
playerPointer = &gameObjects.back();
break;
case '2':
gameObjects.push_back(block);
gameObjects.back().transform.pos = vec((float)x * 100, (float)y * 150, 0);
break;
}
}
}
but when i use
gameObjects.reserve(10000);
the location doesnt change, because its reserved and doesnt need to resize until the size becomes 10000 in this case.
So whats the catch? can you just reserve(1000000000) with no consequences? my RAM usage doesnt skyrocket.
Thanks in advance