TList

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Tue Mar 18 16:15:43 PDT 2008


Sclytrack wrote:
> I was told that adding an array in D uses realloc (Haven't verified this),

It doesn't use C realloc(). In fact, it can't for several reasons:
1) realloc only works on memory allocated by the normal C allocation 
functions (malloc, calloc), which D doesn't use because they don't[*] 
support GC.
2) realloc is supposed[*] to free the original if reallocation succeeds 
but the array was moved, which isn't what's supposed to happen when a D 
array grows (the old one is left for anyone who still has references to 
it; the GC cleans it up if that's not the case).

[*]: Of course, a GC such as Boehm's might fix these issues.
IIRC it provides its own malloc subsystem with a no-op free(). If that 
includes the implicit one in realloc() it could work.


However, the internal routine that is in fact called by the '~=' 
operator is called realloc (but it's a member function) and is exposed 
as std.gc.realloc (Phobos) / tango.core.Memory.gc_realloc (Tango, 
declared extern(C)).
The name is the same, but it has slightly different semantics than the 
standard C version.


More information about the Digitalmars-d-learn mailing list