title: Is it possible to completely disable the default C++ new operator?
body: <p>Because our app has hard performance and memory constraints, our coding standards forbid the use of the default heap &mdash; ie, no <code>malloc</code>, no default <code>new</code>. Every memory allocation has to choose one of a few specific allocators; something like</p>
  
  <pre><code>// declared globally
  void* operator new( size_t size, CustomAllocHeap* heap, const char* perpetrator_name )
  {
    return heap-&gt;Allocate( size, perpetrator_name );
  } 
  // imagine a bunch of CustomAllocHeap's declared globally or statically, thus
  
  Vector* v = new( gPhysicsHeap, __FUNCTION__ ) Vector( 1.0f, 2.0f, 3.0f, 4.0f );
  // or in a class
  Thingy* p = new( this-&gt;LocalArenaHeap, __FUNCTION__ ) Thingy();
  </code></pre>
  
  <p>Although we've maintained good discipline on this with our code, some standard C++ components ( containers, <code>std::function</code> ) covertly make calls to the default <code>new</code> heap, which is very bad. </p>
  
  <p>It would be nice to disable the default <code>new</code> altogether in some way, so that any line of code that implicitly results in a default allocation immediately throws a compiler error. That would let us notice these things right away.</p>
  
  <p>We can obviously make <code>new</code> throw a runtime error <em>ie</em> </p>
  
  <pre><code>void* operator new ( size_t ) { __debugbreak(); return NULL; }  
  </code></pre>
  
  <p>but it would be much better to get warnings about this at compile time. Is that possible?</p>
  
  <p>Our app is built for a fixed platform (x64 with Visual Studio); portability is irrelevant.</p>