<pre>On 08/04/2008, David Adam &lt;<a href="http://www.winehq.org/mailman/listinfo/wine-patches">david.adam.cnrs at gmail.com</a>&gt; wrote:<br>&gt;<i> +    This-&gt;current = This-&gt;current +1;<br></i>&gt;<i> +    HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, This-&gt;matrix, (This-&gt;current +1) * sizeof(D3DXMATRIX) );<br>
</i>&gt;<i> +    if ( This-&gt;matrix == NULL ) return E_OUTOFMEMORY;<br></i><br>&gt; Aside from being a bit suboptimal (doing a realloc on every push),<br>&gt; this probably doesn&#39;t do what you want. Consider what happens to the<br>
&gt; size of the array when you do something like push/pop/push/pop/...etc.<br>&gt; <br>&gt; It would be better to keep track of the current stack size, and then<br>&gt; grow it by a factor (eg. 2 or 1.5) if a push would overflow the<br>
&gt; current stack.<br>&gt; You could also consider shrinking the array again if a<br>&gt; pop would make it use less than a certain percentage of the current<br>&gt; size (eg. a third).<br><br>This would increase the size of the stack exponentially. Would it be better to do this:<br>
Take a stack_size_reference (for instance 32 items)<br>When This-&gt;current =32, then increase the size of the stack of stack_size_reference (that is 64 items now)<br>Then when This-&gt;current is =64, again increase the size of the stack of stack_size_reference (that is 98 items now), and so on....<br>
<br>This would increase the size of the stack linearly instead of exponentially.<br><br>In the opposite, for MatrixStack_Pop, assume that the size of the stack is 98 and This-&gt;current is 64. <br>Then one could shrink the size of the stack from 98 to 98-size_stack_reference that is 64.<br>
&nbsp;<br><br>&gt; You should also assign the result of HeapReAlloc() to This-&gt;matrix<br>&gt; again. <br><br><i><span style="font-style: italic;">I thought that <br><br></span> HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, This-&gt;matrix, ..........);</i><i><br>
</i><br>do exactly what you say<br><br><br>Although it&#39;s quite possible for HeapReAlloc to just grow the<br>&gt; current block without changing its location, there&#39;s no guarantee it<br>&gt; will. The NULL check is useless this way.<br>
<br>Thanks for your very useful feedback.<br><br>David<br><br></pre>