www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Export GC memory manager to C???

reply Robert Persson <r.k.persson gmail.com> writes:
Would it be possible to export GC.malloc(...) as a C function in a DLL, to
use as a garbage collected memory allocator for C ? Or does the garbage
collector not scan outside the boundaries of the DLL?

/Robert Persson, Sweden
Jul 28 2011
next sibling parent "Vladimir Panteleev" <vladimir thecybershadow.net> writes:
On Thu, 28 Jul 2011 13:31:01 +0300, Robert Persson <r.k.persson gmail.com>  
wrote:

 Would it be possible to export GC.malloc(...) as a C function in a DLL,  
 to
 use as a garbage collected memory allocator for C ? Or does the garbage
 collector not scan outside the boundaries of the DLL?

 /Robert Persson, Sweden
To use D's garbage collector in another environment, you'd need to do the following: 1) Use the GC for allocation, naturally 2) Specify the boundaries of the data segment, containing global and static variables 3) Inform the GC of all threads, so that it can scan their stacks 4) If any of your objects require finalization upon collection, you'd need to find a way to integrate that. D's garbage collector is based on the Boehm GC, which was written for C/C++. You may want to use that instead. http://www.hpl.hp.com/personal/Hans_Boehm/gc/ -- Best regards, Vladimir mailto:vladimir thecybershadow.net
Jul 28 2011
prev sibling next sibling parent Timon Gehr <timon.gehr gmx.ch> writes:
Robert Persson wrote:
 Would it be possible to export GC.malloc(...) as a C function in a DLL, to
 use as a garbage collected memory allocator for C ? Or does the garbage
 collector not scan outside the boundaries of the DLL?
The DLL contains code which is dynamically loaded into your program's address space, so the boundaries indicated by you should not exist. I cannot think of a reason why you shouldn't be able to directly expose the GC-interface to C. (As D provides full C-interoperability) Just out of curiosity, what is your use case? -Timon
Jul 28 2011
prev sibling parent Walter Bright <newshound2 digitalmars.com> writes:
On 7/28/2011 3:31 AM, Robert Persson wrote:
 Would it be possible to export GC.malloc(...) as a C function in a DLL, to use
 as a garbage collected memory allocator for C ? Or does the garbage collector
 not scan outside the boundaries of the DLL?
You can use a C++ version of it from the Dscript engine http://digitalmars.com/dscript/index.html
Jul 28 2011