0

Possible Duplicate:
Any reason to overload global new and delete?

Why should we overload/override new and delete in C++?

Give me an example of situation in which we should overload/override new, new[], delete or delete[].

Community
  • 1
  • 1
user366312
  • 16,949
  • 65
  • 235
  • 452
  • 2
    And: http://stackoverflow.com/questions/7149461/why-should-one-replace-default-new-and-delete-operators – tinman Sep 06 '11 at 08:25

2 Answers2

2

This sounds a bit like a homework assignment. Nevertheless, here are two uses off the top of my head:

  • For profiling purposes. For instance, we use it in a library as a poor-man’s valgrind to track memory leaks.
  • To implement a custom allocator (e.g. a pool allocator) for your objects. Usually I’d implement an allocator for this, though.
Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
0

To provide your implementation of allocating/deallocating memory. new/delete are very general. When you know how your application is going to use memory you can provide more efficient version of new/delete. That would be very simple for example if you used a lot of small object.

Another usage would be to provide memory leak detection.

That's not very often used mechanism - at least in my experience.

Łukasz Milewski
  • 1,897
  • 13
  • 14