c++ saving object allocation and deletion -
i'm working on little game, , need somes class/struct allocated , deleted often. i'm wondering way save deletion, maybe putting delete object in container, , try pick in container when want allocate instance of class.
i'm thinkin overload of new , delete operator. have little problem, if overload delete operator (to put "deleted" object in container), how delete it? should pass throught proper function that?
there 2 ways go that
1) pool of objects. when "allocate" take object pool , when deallocate return pool. not transparent implementation not hard.
2) create custom allocator classes/structs. preallocate memory in big buffer , when need allocate take memory there , when need deallocate return memory (the actual mechanism you). bit harder implement can more transparent.
check following links ideas
- http://www.drdobbs.com/policy-based-memory-allocation/184402039
- http://www.boost.org/doc/libs/1_57_0/doc/html/interprocess/allocators_containers.html
- http://en.cppreference.com/w/cpp/memory/allocator
- http://yosefk.com/blog/why-custom-allocatorspools-are-hard.html
also, while @ it, there great book alexandrescu
http://www.amazon.com/modern-design-generic-programming-patterns/dp/0201704315
a bit old, exceptional nevertheless , has section memory management/allocator.
Comments
Post a Comment