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