Re: Encapsulate C struct/toll-free bridging?
Re: Encapsulate C struct/toll-free bridging?
- Subject: Re: Encapsulate C struct/toll-free bridging?
- From: Allan Odgaard <email@hidden>
- Date: Wed, 10 Mar 2004 01:32:25 +0100
On 10. Mar 2004, at 0:12, Clark Cox wrote:
Alignment is irrelevant with respect to the isa pointer, as C (and
therefore Objective-C) guarantees that there is no padding before the
first structure member.
The isa pointer points to a structure which list all the instance
variables, giving their offset from the object pointer (but I guess
these will only be used if the object is submitted to access through
KVC).
But another problem is the reference counting (if the object should be
used as an ObjC object, I guess it really ought to implement retain and
release) -- to me it is not clear from the documentation where the
reference count is stored, but there are functions in Foundation to
increment/decrement it and extract it, and there is also a function to
allocate an object from an Class structure, allowing for "extra bytes".
So although this is speculation, one solution could be to use this
NSAllocateObject function and provide sizeof(c_structure) as the "extra
bytes" argument. That should give you an ObjC object where your
c-structure can be found "after" the instance variables (i.e. the isa,
declared by NSObject).
Personally though, I wonder what the reason is for the OP to want this
"bridging"? I mean, writing "[obj someMethod]" instead of
"someFunc(obj)" has limited advantages :) especially since the
implementation is a bit hacky IMHO...
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.