title: Is there a way to have an array of uninitialized classes that aren't destructed when delete[] is called?
body: <p>I'm implementing an object pool with type erasure so that pools can be stored in collections and can store other pools. The functionality is in place, but also features a memory leak coming from not deleting the pool itself. I have the following code:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>template &lt;typename T&gt;
  struct ObjectPool::PoolModel final : PoolConcept {
      PoolModel(uint size) : pool( new T[size](), [](T _[]){ /*Problem!*/}) {}
      virtual ~PoolModel() {}
  private:
      std::unique_ptr&lt;T[], std::function&lt;void(T[])&gt;&gt; pool;
  };
  </code></pre>
  
  <p>Fittingly, "Problem!" is where my problem is. You may wonder why I've substituted uinique_ptr's default delete for one that does nothing. This is because the pool is filled with completely bogus data at destruction time and so when a pool of pools is destroyed (or any pool of objects carrying smart pointer's or other objects with destructors) then the array delete will call the destructor of each class and follow up by deleting a bogus smart pointer which causes a segfault. So I substituted the noop destructor and everything functions peachy.</p>
  
  <p>Hence the memory leak. I've gotten rid of the default delete and so each pool object leaves behind it's pool. I have tried "::operator delete[](arr);" in the "Problem!" spot, since it supposedly deletes an array without calling the object's destructors, but that yields "munmap_chunk(): invalid pointer." I'm trying to find a c++ way to do this and not need to resort to malloc and free. Furthermore I'd like to know if there's a way to allocate the array in the first place without calling a default constructor for each array member and just leave them uninitialized.</p>