1

Recently, I was writing a custom memory allocator,See this article in detail custom memeory alloc..

thanks to the answer of David Hammen,now i can free the memory of polymorphic objects correctly. then seem i can use MYNEW macro to alloc memory and construct object, use MYDEL macro to destroy object and free memory,also can be memory tracking.

but I'm not sure whether it can be used in a complex project environment(eg:complex multiple inheritance design..), whether there are hidden dangers ?

NOTE: i am not ask for how to do memory manager, how to overload operator new/delete(global or for class), I just want to know whether there are problem of this method in the actual project development. Thanks for any answer.

Community
  • 1
  • 1
xfxsworld
  • 283
  • 1
  • 10
  • 1
    imo, "custom memory allocator" is automatically dangerous. – Reinderien Dec 06 '12 at 03:11
  • Why are you doing a custom memory allocator instead of using the default? (There are multiple reasons, I want to know which apply to you.) If you need STL to use your allocator, then you need to define a std::allocate<> type template. – brian beuning Dec 06 '12 at 03:42
  • @brian beuning for two reason: 1. alloc tracking. 2. manage memory allocator. eg:use nedalloc lib to optimize new/delete on win-xp os. as you said, when i need STL custom allocator, i will define a STLAllocator template, but also use MYNEW/MYDEL to alloc/dealloc memory inner. – xfxsworld Dec 06 '12 at 03:52
  • This question asks for discussion. There is no definitive answer. Probably should be closed. – Jive Dadson Dec 06 '12 at 04:30
  • Why not have a look at Google's tcmalloc from gperftools (http://code.google.com/p/gperftools/)? It even allows you to profile your code easily. It kind of acts as a garbage collection for small object allocation. – gvd Dec 06 '12 at 06:45
  • before I forget, with tcmalloc you only need to link to it and it automatically starts using it. Ofcourse, it depends on your need. For some applications you will see a performance improvements, for others you won't – gvd Dec 06 '12 at 06:56

0 Answers0