Less known std.gc

Christopher Wright dhasenan at gmail.com
Mon Nov 19 10:34:13 PST 2007


Jarrett Billingsley wrote:
> "Christopher Wright" <dhasenan at gmail.com> wrote in message 
> news:fhs891$277v$1 at digitalmars.com...
> 
>> There's nothing in any of that that allows you to allocate memory and then 
>> say, "Let the garbage collector handle this from now on." I guess I have 
>> to start writing code to delete the objects that I malloc'd; I have an 
>> embarrassing amount of memory leaks now.
> 
> Oh yes there is :)  std.gc.alloc, std.gc.realloc, and std.gc.extend all 
> allow you to allocate arbitrary blocks of GC'ed memory.  Also if you 
> allocate memory with alloc (and possibly realloc?) you can flag the block as 
> containing or not containing pointers using std.gc.hasPointers(ptr) and 
> std.gc.hasNoPointers(ptr). 

My mistake; thank you. That's why I didn't see a 'free' entry in std.gc.

Is there any way to hook up a destructor, besides allocating memory with 
a constructor? I ask purely out of academic interest; I allocate objects 
manually in some cases, but I don't need to use destructors with them, 
currently.


More information about the Digitalmars-d-learn mailing list