I'm writing a game with a minecraft-style world. Minecraft stores all it's blocks in a 'Chunk' system consisting of 16x16x256 blocks per chunk. My program does the same but with 16*16*infinite blocks in a std::map consisting of layers.
Change the type of your member variables to fully support value semantics and follow the rule of zero: std::map<long, std::vector<Voxel>> m_chunkContents;
The special member functions (copy-. move-, construction, assignment, destruction) are correct by default in the above case.
How do you check the memory usage? The Windows Task Manager is no good for this. Processes often hang on to memory that has been freed, for efficiency reasons, so that it can be reused later. If your world is not big enough it might not be worth releasing it back to the OS. You could try making your world bigger and see if that makes a difference, otherwise I recommend using a debugger to find memory leaks.
Change the type of your member variables to fully support value semantics ..
I'd prefer not to. Is there a reason for that?
How do you check the memory usage? The Windows Task Manager is no good for this.
You have an alternative?
EDIT:
After regenerating my terrain for like 10 times, the taskmanager showed me 1.5GB of memory usage. I'm not storing the data very efficient, but thats another problem I'll face another time. http://i.imgur.com/R2tTDTf.png
Yes. Value semantics eliminates ownership problems (the container owns them, values in the container have the storage duration of the container) and leaves you unconcerned about the identity of objects in the container. It's also less error-prone, because indirection increases complexity.
Value semantics should be preferred when sufficient. If you care about the runtime identity of the object because e.g., Voxel is polymorphic, then you can use something like boost::ptr_vector<Voxel> or std::vector<std::unique_ptr<Voxel>> to get that benefit without having to concern yourself with the rule of five.
Maybe you have another reason to store references (space optimization?), but you should share that reason.
At the very least, avoid storing owning raw pointers in STL containers.
By the way, I don't see a problem with the Chunk destructor. It's just a bit overcomplicated. There is no need to call clear() because the destructors of std::map and std::vector will take care of that anyway.
1 2 3
for(auto it = m_chunkContents.begin(); it != m_chunkContents.end(); it++){
delete(it->second);
}