Note that there are some explanatory texts on larger screens.

plurals
  1. PODo I have to allocate everything on the heap (that gets stored within) heap containers?
    text
    copied!<p>I'm overriding the new operator to manually allocate heap space when using the new keyword.</p> <p>Usually using a stack-allocated heap container with pointers to its items-</p> <pre><code>CArray&lt;CObject*&gt; objects; </code></pre> <p>-is fine. but I'm picky and I want to make buffers-</p> <pre><code>CArray&lt;CObject&gt; objects; </code></pre> <p>-that let me modify POD types. So, I allocate them on the stack which is naturally suited for their use:</p> <pre><code>CVertex vertex; objects.push_back(vertex); </code></pre> <p>But it corrupts the heap (I've had one of those bad weeks) and gives a crazy error:</p> <pre><code>0xC0000017: Not Enough Quota. </code></pre> <p>I pre-allocate the array objects and then use the = operator internally in <strong>push_back()</strong>.</p> <p>I solved the problem by allocating the temporary objects on the heap and then adding them to the array. But it doesn't seem right, and I just don't get it.</p> <p>As requested, some code:</p> <pre><code>CArray::push_back( T&amp; newElement ) { m_internalElements[allocatedSize] = newElement; allocatedSize++; } CArray::preallocate_and_initialize( size_t itemCount ) { T* newInternalElements = mem::allocate_and_initialize( T, itemCount ); //copy over } </code></pre> <p>Note that it all works with heap allocated <strong>CVertex</strong>'s as I am using these objects in a binary search of the buffer elements (finding the right item in the index buffer for a given vertex) and it builds a mesh perfectly fine!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload