How to save RAM in D programs (on zero initialized buffers)

Martin Nowak dawg at
Tue Feb 7 13:13:04 PST 2012

On Tue, 07 Feb 2012 21:24:40 +0100, Marco Leise <Marco.Leise at> wrote:

> Am 07.02.2012, 21:11 Uhr, schrieb Nick Sabalausky <a at a.a>:
>> Is void initialization not good enough?
>> IIRC it's something like:
>> ubyte[] buf = void;
> That gives me a) no buffer, who's pointer is b) not initialized to null.
> I want instead a defined pointer, to a valid array, that is initialized  
> to zero.
> Anyway, I think the flaw in my proposal is the use of a GC. Since we  
> don't get the memory directly from the operating system, but from a  
> memory pool in the GC, it is generally 'recycled' and already used  
> memory. It has to be zeroed out manually, unless there was a way to tell  
> the OS to rebind some virtual memory addresses in our program to this  
> magic 'zero page'.

You usually don't need initialized memory from the GC.
The calloc behavior is still pretty interesting.

More information about the Digitalmars-d mailing list