A few questions regarding GC.malloc

Sean Kelly via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Sep 25 15:03:53 PDT 2014


On Thursday, 25 September 2014 at 21:43:53 UTC, monarch_dodra 
wrote:
> On Thursday, 25 September 2014 at 20:58:29 UTC, Gary Willoughby 
> wrote:
>> A few questions regarding GC.malloc.
>>
>> When requesting a chunk of memory from GC.malloc am i right in 
>> assuming that this chunk is scanned for pointers to other GC 
>> resources in order to make decisions whether to collect them 
>> or not?
>
> By default, yes, but you can use BlkAttr.NO_SCAN if you do not 
> want that (eg, if you want to store integers). As a rule of 
> thumb, you can use hasIndirections!T to know if or if not to 
> scan (that's what most of phobos relies on).

Yep.  It's generally just easier to do a "new T[]" when you want 
a block to ensure that the proper flags are set, as GC.malloc is 
conservative in terms of the flags it sets.

>> What does BlkAttr.FINALIZE do when used in the GC.malloc call?
>
> I have no idea. I think its for classes though, since we 
> (currently) don't finalize structs anyways.

Yes it's for memory blocks containing class instances.  It 
basically tells the GC to call Object.~this() when collecting the 
block.


More information about the Digitalmars-d-learn mailing list