Re: Objective-C++ and NSInvocation (or IMP)
Re: Objective-C++ and NSInvocation (or IMP)
- Subject: Re: Objective-C++ and NSInvocation (or IMP)
- From: Scott Ribe <email@hidden>
- Date: Wed, 30 May 2007 12:03:49 -0600
- Thread-topic: Objective-C++ and NSInvocation (or IMP)
I haven't looked at this in a while, but if I recall correctly, the
NSInvocation stuff does not work with any argument more than 8 bytes in
size, meaning that even plain C structs do not work. (Remember, Objective-C
never pass objects by value, every object is a pointer; I assume it works
with 8 byte values to get doubles through.) Pointers to C++ objects work
fine, as long as you perform the appropriate casting at the appropriate
time, which can be eased greatly with templates and a helper class.
I thought about evil things such as using placement-new syntax on locally
malloc'd memory at the creation of the invocation, combined with explicit
destructor call and free at dealloc of the invocation, so that for instance
things like smart pointers could be used and work correctly when the
creation and invocation occur on different threads. However, I did not go
down that path ;-)
I did create a templated helper class to wrap up the creation of
NSInvocation objects, and in it I used some of the Loki type traits features
to make sure that any attempt to create a wrapped NSInvocation with
arguments that it won't handle will generate a compile-time error. My
primary purpose of doing this was support for extending Loki's functors to
encapsulate method calls to Objective-C objects.
Sooner or later, I'm going to have to emulate pass-by-value of C++ objects
through NSInvocations. Right now I'm just letting certain things leak,
because there's not much memory involved and no resource-locking issues, but
eventually this constraint is going to have to get fixed.
--
Scott Ribe
email@hidden
http://www.killerbytes.com/
(303) 722-0567 voice
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden