overloaded new/delete useful?
I was wondering if people actually overload these operators, and what reason would there be for doing so? Isnt the default one good enough?
Memory logging / instrumentation is one possible usage, also providing customized allocators (object pools, chunked etc) can provide real performance benefits and avoid fragmentation of the global heap.
So yes, there can be a real benefit in overloading them but it's actually quite safe to not do so until, as always, profiling shows otherwise.
So yes, there can be a real benefit in overloading them but it's actually quite safe to not do so until, as always, profiling shows otherwise.
you would overload it if you were designing a memory manager and you wanted full control over what went on behind the scenes.
The global new and delete operators - rarely. To customize a class's memory allocation - more often. See for example, Loki::SmallObject.
It's a convenient way to record memory allocations/deallocations without having to use a custom function.
I did this a while back to keep track of how much memory was dynamically allocated at any given time. With a simple "bookmark" system I could track down memory leaks easily, though I never actually used the sytem and eventually trashed it because it was taking up space [smile]
I did this a while back to keep track of how much memory was dynamically allocated at any given time. With a simple "bookmark" system I could track down memory leaks easily, though I never actually used the sytem and eventually trashed it because it was taking up space [smile]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement