digitalmars.D - Hooking the GC?
- %u (6/6) Jan 02 2011 Hi,
- Simen kjaeraas (6/12) Jan 03 2011 You're gonna have to add such functionality to the GC by yourself, I'm
- Vladimir Panteleev (9/12) Jan 03 2011 FWIW, Diamond ( http://github.com/CyberShadow/Diamond ) hooks various GC...
- Steven Schveighoffer (5/12) Jan 03 2011 If you want to hook the GC, you probably have to add your own code to th...
- %u (4/4) Jan 03 2011 It doesn't have to be at run-time, I can add code to the GC too. So _d_n...
- Vladimir Panteleev (6/13) Jan 04 2011 _d_newclass invokes the GC's malloc downstream. It's just that at
- %u (2/3) Jan 04 2011 you know the class typeinfo being allocated.
Hi, Is there any way to add a hook to the garbage collector in D, so that I can be immediately notified (for example) when an object is created? (I'm aware that this could cause infinite recursion/deadlock if I try to allocate memory, but that's all right, I'm fine with that.) Thank you!
Jan 02 2011
%u <wfunction hotmail.com> wrote:Hi, Is there any way to add a hook to the garbage collector in D, so that I can be immediately notified (for example) when an object is created? (I'm aware that this could cause infinite recursion/deadlock if I try to allocate memory, but that's all right, I'm fine with that.)You're gonna have to add such functionality to the GC by yourself, I'm afraid. Shouldn't be too hard though, depending on what sort of info you require from the hook. -- Simen
Jan 03 2011
On Mon, 03 Jan 2011 05:34:55 +0200, %u <wfunction hotmail.com> wrote:Is there any way to add a hook to the garbage collector in D, so that I can be immediately notified (for example) when an object is created?FWIW, Diamond ( http://github.com/CyberShadow/Diamond ) hooks various GC functions, but it's an ugly hack that breaks with multi-threaded programs (and the module is D1 and x86-only). A better run-time solution (not involving modifying Phobos/druntime) would need a instruction-length disassembler. -- Best regards, Vladimir mailto:vladimir thecybershadow.net
Jan 03 2011
On Sun, 02 Jan 2011 22:34:55 -0500, %u <wfunction hotmail.com> wrote:Hi, Is there any way to add a hook to the garbage collector in D, so that I can be immediately notified (for example) when an object is created? (I'm aware that this could cause infinite recursion/deadlock if I try to allocate memory, but that's all right, I'm fine with that.) Thank you!If you want to hook the GC, you probably have to add your own code to the GC. Start with _d_newclass in druntime's src/rt/lifetime.d -Steve
Jan 03 2011
It doesn't have to be at run-time, I can add code to the GC too. So _d_newclass would be *almost* what I'm looking for, except that it doesn't work for memory allocated using GC.malloc()... so I'd have to hook in multiple places I guess. Thanks for the info.
Jan 03 2011
On Tue, 04 Jan 2011 01:06:39 +0200, %u <wfunction hotmail.com> wrote:It doesn't have to be at run-time, I can add code to the GC too. So _d_newclass would be *almost* what I'm looking for, except that it doesn't work for memory allocated using GC.malloc()... so I'd have to hook in multiple places I guess. Thanks for the info._d_newclass invokes the GC's malloc downstream. It's just that at _d_newclass, you know the class typeinfo being allocated. -- Best regards, Vladimir mailto:vladimir thecybershadow.net
Jan 04 2011
_d_newclass invokes the GC's malloc downstream. It's just that at _d_newclass,you know the class typeinfo being allocated. Ohh I see, okay, thank you!
Jan 04 2011