Re: Distributed Objects help - a fun hack
Re: Distributed Objects help - a fun hack
- Subject: Re: Distributed Objects help - a fun hack
- From: Miguel Morales <email@hidden>
- Date: Tue, 4 Sep 2001 10:33:32 -0700
Dear Peter,
DO works VERY hard to keep everything thread safe (even object double
pointers get dereferenced). This is the reason for the NSDistantObjects
you are getting. Now there are situations where you can guarantee that
an object will not be accessed by multiple threads, and you don't want
the overhead of using the 'bycopy' keyword. The hack I have found to
this is the following set of calls, making use of casting so that the DO
system does not know an object is involved. I have no idea if this will
survive various upgrades, but it works on both OS X 10.0.4 and GNUStep
under Linux without any problems (just a compiler warning). If anyone
out there knows of a better method, I'd love to hear it.
//Sending an object pointer
[otherThreadProxy hereIsTheObject: (unsigned long
int)objectToBeSent]; //cast the object (really and object pointer, so
a memory address) to be sent as an unsigned long int
//in the object pointed to by proxy (in another thread)
-(oneway void)hereIsTheObject: (unsigned long int)objectPointer
{
ExpectedClass *myNewObject;
//now cast back to get an object
myNewObject = (ExpectedClass *)objectPointer;
//myNewObject can now be used normally since it points to the right
memory location
.... (your code here)
}
Lots of caution should be used here - it is a hack. You have to be
careful about allocation/deallocation issues, thread safety, and of
course using this between objects in different memory spaces will test
the memory protection mechanisms of our new kernel :-)
-Miguel
On Friday, August 31, 2001, at 10:20 PM, cocoa-dev-
email@hidden wrote:
Message: 6
Date: Fri, 31 Aug 2001 21:20:01 -0400
From: Peter Ammon <email@hidden>
To: email@hidden
Subject: Distributed Objects help
I'm trying to write a generalized thread wrapper with a built-in DO.
I'd like to have a method callable from a spawned thread that would make
an arbitrary target object perform an arbitrary target method in the
main thread. I pass the target object, the selector, and the parameter
to the proxy, but when they are received in the main thread, the target
and the parameter are NSDistantObjects rather than the objects I sent.
I think this is causing problems! How can I make NSConnection and
friends send the pointers to the objects, rather than construct proxies
for them?
Thanks.
-Peter