title: What is the benefit of overloading 'new' and 'delete' for custom memory allocation in game engines?
body: <p>I'm in the process of porting my game engine from Java to C++. I've been doing a lot of research on custom memory allocators as I now need to worry about memory management. Every article that I've read on the topic says that you should overload the <code>new</code> and <code>delete</code> operators. However, these overloaded operators usually just delegate to and call a custom function that handles the memory allocation. Furthermore, macros are commonly used such as:</p>
  
  <pre><code>#define New(className, size, description) customNew(className, size, description, __FILE__, __LINE__)
  </code></pre>
  
  <p>which never even use the overloaded <code>new</code> operator, and simply calls the custom method. I understand how the macros are useful as you can get the filename and line numbers nicely, but why overload <code>new</code> and <code>delete</code> if in code you're simply going to use the macro <code>New</code> and not the operators.</p>
  
  <p>Also, overriding (not overloading) the default <code>new</code> seems somewhat pointless when our custom allocator may want to know additional information such as a description, a filename and line numbers. We can't possibly know that information on a standard invocation of <code>new</code>and can't delegate it to our <code>customNew</code> in a meaningful way.</p>
  
  <p>I'm failing to see what the great benefit is of overloading and overriding these operators.</p>
  
  <p>It seems to me that calling:</p>
  
  <pre><code>customNew(className, size, desc, file, line);
  </code></pre>
  
  <p>is more intuitive than calling the overloaded <code>new</code>:</p>
  
  <pre><code>new (size, desc, file, line) className();
  </code></pre>
  
  <p>Finally, if I were to override and overload, where is the best place to do so? Doing it per class is obnoxiously tedious. Can it be done by namespace? I plan on having separate projects for each sub-system so that they can be maintained independently. How would I facilitate overriding and overloading across the projects and then within the game's project? Pardon my C++ n00bishness. It's been a while.</p>