Prevent Garbage Collector

Jeroen Bollen jbinero at gmail.com
Sat Jan 4 18:08:54 PST 2014


On Sunday, 5 January 2014 at 01:23:58 UTC, Adam D. Ruppe wrote:
> On Sunday, 5 January 2014 at 01:10:29 UTC, Jeroen Bollen wrote:
>> Is there a way to tell it to not initialize it?
>
> I'm not sure of any except using the primitives. You can malloc 
> GC memory from GC.malloc (works the same way as C malloc, 
> except you don't have to free it yourself; the GC does it). 
> GC.malloc doesn't initialize the memory.
>
> http://dlang.org/phobos/core_memory.html#malloc
>
>
> I don't think there's a way to tell new not to zero it out 
> though...
>
>> Is it safe to use foreach on it if it isn't initialized?
>
> Yeah, the contents will be random, but you are setting it 
> anyway so that doesn't matter.

As GC.malloc returns a pointer, how does it know when it should 
garbage collect the allocated space?


More information about the Digitalmars-d-learn mailing list