Allocating delegate on heap?

Rick Mann rmann-d-lang at latencyzero.com
Mon Feb 19 00:46:52 PST 2007


It appears that a delegate can't be directly allocated on the heap; only as part of a struct, class or array. This is rather annoying.

I'm trying to wrap a C api for event handling (on Mac OS X). In it, you register event handlers as C-linkage callback functions, and you register a bit of "user data" (4 bytes, usually a pointer to something). In your callback, the user data used when you registered is provided, and you typically cast it to your struct or class or whatever.

I'd like to use a delegate as my user data, but it's 8 bytes. So I need to pass a pointer to the delegate, and I need the delegate to live longer than the scope of the code that registered the callback in the first place. However, I don't see how to create a delegate on the heap. Is there any way? (Other than to wrap it in some clunky struct?)

TIA,
Rick


More information about the Digitalmars-d-learn mailing list