C++, D: Dinosaurs?

Robert Fraser fraserofthenight at gmail.com
Tue Nov 4 00:01:51 PST 2008


Tony wrote:
> "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? Just allowing me to replace "getmorecore()" or something like that 
> and then having the collector on top of that is unacceptable to me. I think 
> you may be saying that dynamic memory is in every program, which again is 
> not acceptable to me.
> 
> Really, memory control is a key issue when choosing a language for me 
> anyway. I require that level of closeness to the hardware. Anything less is 
> too 4GL-like for me.
> 
> Tony 

Whenever memory is allocated (i.e. "new", AA use, append to a dynamic 
array), the compiler generates a call to a GC function. You can replace 
this with your own allocator. In other words, YES -- you can remove the 
_entire_ GC and replace it with your own allocation scheme, but you must 
be careful not to use AAs or the ~ (or ~=) operator carelessly, since 
these depend on the allocator. In D2, you need to worry about closures, too.



More information about the Digitalmars-d mailing list