digitalmars.D - Export GC memory manager to C???
- Robert Persson (4/4) Jul 28 2011 Would it be possible to export GC.malloc(...) as a C function in a DLL, ...
- Vladimir Panteleev (16/21) Jul 28 2011 To use D's garbage collector in another environment, you'd need to do th...
- Timon Gehr (7/10) Jul 28 2011 The DLL contains code which is dynamically loaded into your program's ad...
- Walter Bright (3/6) Jul 28 2011 You can use a C++ version of it from the Dscript engine
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
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, SwedenTo 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
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
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