Understanding the GC

Sean Kelly sean at invisibleduck.org
Thu Jan 31 08:28:59 PST 2013


GG.reserve can be handy for this. It tells the GC to pre allocate a block of memory from the OS. 

On Jan 31, 2013, at 7:12 AM, "Steven Schveighoffer" <schveiguy at yahoo.com> wrote:

> On Wed, 30 Jan 2013 03:15:14 -0500, Mike Parker <aldacron at gmail.com> wrote:
> 
>> My understanding is that the current implementation only runs collections when memory is allocated. Meaning, when you allocate a new object instance, or cause memory to be allocated via some built-in operations (on arrays, for example), the GC will check if anything needs to be collected and will do it at that time. I don't know if it's run on every allocation, or only when certain criteria or met, and I really don't care. That's an implementation detail. The D language itself does not specify any of that.
> 
> This isn't quite accurate.
> 
> The GC first checks to see if there is a free block that would satisfy the allocation, and if it can't find one, THEN it runs a collection cycle, and if then it cannot allocate the block from any memory regained, it then asks for more memory from the OS.
> 
> This can lead to the collection cycle running quite a bit when allocating lots of data.  I don't know if there are any measures to mitigate that, but there probably should be.
> 
> -Steve


More information about the Digitalmars-d-learn mailing list