Today I finished all the allocators I had in mind.
The stack allocator prepares a huge chunck of memory, and each object is allocated on top of it. Deallocating an object does nothing, the only way to remove an object from the top is calling the pop method. The actual deallocation is called when the stack pointer is set back to zero.
It's important to notice that the destructor of an object is still called, so if you really want to destroy an object, a hole in the memory will be left, but this is an obvious downside in stack allocators.
The Pool allocator is not a "global" allocator like the stack allocator and the mallocator. You can create multiple pools, and each one of them can be allocated using other allocators.
To test it out I allocated on the Stack Allocator a pool of Particle3D used by the particle emitter.
To wrap things up I gave a complete set of debug messages to each allocator, and they can be activated or deactivated with a preprocessor directive.
Nessun commento:
Posta un commento