No subject


Thu Mar 29 20:50:10 PDT 2007


“... compacting the remaining used memory by copying the allocated objects (called a
 copying collector)”

Suppose I do following:

alias extern(C) void function(void *context) callback;
extern(C) void xyz(callback handler, void *context);
class A
{
	void foo()
	{
		// some stuff goes here
	}
	static extern(C) void handler(void *context)
	{
		A a = cast(A)context;
		a.foo();
	}
	void test()
	{
		// call xyz - both handler address and this will be stored internally in the C-library
		xyz(&handler, cast(void*)this);
	}
}

Should I std.gc.addRoot to the address of the callback function in order to prevent the GC from moving the object? Furthermore, will the GC honor this root if it points to a member method of an instance of an object? And last question - is this one correct: std.gc.addRoot(cast(void*)this)?

If above is answered somewhere, please point me to it. I searched this forum, but to no avail.
Thanks,
-- teo


More information about the Digitalmars-d-learn mailing list