overloaded new/delete useful?

Started by
3 comments, last by nilkn 18 years, 10 months ago
I was wondering if people actually overload these operators, and what reason would there be for doing so? Isnt the default one good enough?
Advertisement
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.
HardDrop - hard link shell extension."Tread softly because you tread on my dreams" - Yeats
you would overload it if you were designing a memory manager and you wanted full control over what went on behind the scenes.
We have youth, how about a fountain of smart.e4 e5 f4 d5
The global new and delete operators - rarely. To customize a class's memory allocation - more often. See for example, Loki::SmallObject.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
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]

This topic is closed to new replies.

Advertisement