In reviewing my code I see some "ugly" structure I use, in a class (called "map") I have a vector which contains a "data" class:
std::vector<PointerToHUGEClass> vector;
Where PointerToHUGEClass is just like the name describes. (though the object pointed too is also owned by the map class, and created with the "new" parameter in the constructor). This works all good (at the moment). However I still feel it is more of a work-around.
The only reason I am using a "PointerToHUGEClass" instead of just "HUGEClass", is because I wanted to make sure the object is not declared from the stack. This was made however before I understood allocaters. Now I feel it is more or less the task of the allocator to ensure the memory isn't declared from the stack.
My questions:
- Am I correct in assuming the allocator is responsible for the memory management from the items? (And making sure it is declared from stack/freestore/heap/whatever)
- What does the std::allocator do? - Does it declare from the stack, or from the heap?
- (follow up from previous question): if I copy an item declared in the stack to the datastructure is it still declared in the heap?
Thanks again, paul23