[D-runtime] Proposed changes to GC interface

Fawzi Mohamed fawzi at gmx.ch
Fri Aug 6 17:45:31 PDT 2010


I would basically reduce all alloc functions to

extern (C) void* function(void* oldP,size_t minBytes, size_t  
optimalBytes, size_t minAlign, TypeInfo,int flags,size_t*  
realSizeInBytes) gc_realloc;

if one would like to be a bit less extreme also an alloc function  
could be added, but I will describe only realloc here.

Allocation is a "heavy" function, and I don't expect that having less  
arguments would make it faset.

This is the interface functions, wrappers could be offered on the top  
of this if one prefers calloc,... this is a low level interface of the  
gc that should be pluggable (at least at link time), so having it  
simple is an advantage imho.

now to the behaviour of the function.

If oldP is not null tries to preserve the flags of it (but no  
guarantee is given, it is ok to use the flags from the typeinfo, this  
would allow switching from storing flags to typeinfo when enlarging an  
array).

If oldP is null the flags are taken from the TypeInfo.

minN gives the minimum number of bytes to allocate, minAlign the  
minimum aligment requested (this should be equal or larger to the  
type .alignof, note that I expressely avoid asking the typeinfo for  
it) One might want a larger alignment that the default for the  
typeinfo (one could avoid this argument by constructing special  
typeinfos, but I think that it is better to have it).

Typeinfo is always required, and there are two special typeinfos  
aliases that have addesses 0 and size_t.sizeof and represent ubyte and  
void (which should be which I don't know).

The flags are a bit field with
- NoInit (the memory should not be initialized)
- NoMove (the pointer should not be moved: only in place resizes)
- InitMax (as much as possible of the allocated memory should be  
declared as actively used/initialized)

The two aliases make it possible to easily use the functions also from  
C.

realSizeInBytes will contain the real allocated size (useful in  
combination with the InitMax because then realSizeInBytes/T.sizeof  
will be initialized, or when minBytes is different from optimalBytes).
It is an error to use the extra allocated memory without having  
initialized it

I think compatibility with Tango is not important, but being able to  
build/use druntime standalone is.

Some GCs might have more dependencies so continuing the "interface for  
the runtime"/plugin approach is the way to go

Fawzi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/d-runtime/attachments/20100807/c91977f5/attachment.html>


More information about the D-runtime mailing list