C++, D: Dinosaurs?

Nick Sabalausky a at a.a
Tue Nov 4 00:17:32 PST 2008


"Tony" <tonytech08 at gmail.com> wrote in message 
news:geogvj$1p5r$2 at digitalmars.com...
>
> "Robert Fraser" <fraserofthenight at gmail.com> wrote in message 
> news:geo5p6$12gk$1 at digitalmars.com...
>> Tony wrote:
>>> (one HAS to use GC with D, right?)
>>
>> No. Well, the compiler generates calls to allocate & free memory, but you 
>> can replace those calls with whatever you want. See Tango's (druntime's) 
>> "stub" GC, which just reroutes compiler-generated calls to GC methods to 
>> malloc() and free(). You can implement your own "GC" or whatever 
>> management scheme you want (in fact, if you're writing, say, a device 
>> driver in D, you would want to use a custom allocator like this and not 
>> the built-in GC).
>
> Please clarify for me the mem mgmt of D: is the garbage collector optional 
> or not?

Yes, it can be ripped out, replaced, whatever. It's slightly hacky, but it's 
perfectly doable. I did it a few years ago when I was playing around with 
using GDC with DevKitARM for GBA.

IIRC, you just go into "extern (C) int main(size_t argc, char **argv)" in 
the internal portion of phobos/tango/druntime or wherever it lives now and 
comment-out the calls to "gc_init()" and "gc_term()". You might also need to 
call "gc.disable()" or something (don't really remember). And then if you 
still want to use "new" and/or "delete" with your own memory manager, you 
can use D's class allocator and deallocator feature 
(http://www.digitalmars.com/d/1.0/class.html#allocators). I assume you could 
probably plug those class allocators/deallocators directly into the internal 
object class if you wanted. 





More information about the Digitalmars-d mailing list