Memory leak with dynamic array

Steven Schveighoffer schveiguy at yahoo.com
Tue Apr 13 06:16:55 PDT 2010


On Tue, 13 Apr 2010 08:56:03 -0400, Steven Schveighoffer  
<schveiguy at yahoo.com> wrote:


> If you don't use reserve, here is what happens during the loop:
>
> 1st append: The smallest block possible to hold 1 double is found and  
> allocated
> 2nd append: If the block holding the first double can hold 2, the  
> "allocated" size of the block is increased to 2 doubles.  Otherwise, the  
> smallest block possible to hold 2 doubles is found and allocated.
> ...
>

Assuming you may ask questions about this, it's not an exact description  
of what happens.  The append code and GC are smarter about it than this, I  
just wanted to explain it in an easy-to-understand way :)  The real code  
uses algorithms to determine optimal grow sizes and can extend into  
consecutive blocks if possible.

-Steve


More information about the Digitalmars-d-learn mailing list