Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Mon Oct 15, 2018 4:29 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Do I Need To Call REALLockObject?
PostPosted: Mon Oct 20, 2008 8:44 am 
Offline

Joined: Wed May 10, 2006 5:16 pm
Posts: 19
Location: Lawrenceville, NJ
I have a plugin class that creates objects of another class by calling REALnewInstance. The plugin keeps a list of these objects:
REALobject myObjsREAL[ 16 ];

myObjsREAL[0] = REALnewInstance( "CThing" );


The RB application makes a call into the plugin to get one of these objects from the list:
Dim thing As CThing
thing = GetFirstThing()


The plugin implements GetFirstThing as:
static REALObject
GetFirstThing( REALobject obj )
{
return( myObjsREAL[0] );
}

static REALmethodDefinition _methName[] = {
{ (REALproc)GetFirstThing, REALnoImplementation, "GetFirstThing() As CThing" } };


When the plugin creates the object, REALnewInstance returns a locked object (right?)

Does the plugin need to call REALLockObject in GetFirstThing before it returns the object to RB?

I was thinking "no" because the RB code does not call "thing = new CThing", just thing = GetFirstThing().
Since the RB code does not create the object it would just use it as is. Or else lock it and unlock it.

The RB code wouldn't assume that it came locked and just unlock it after it was done would it?

REALBasic 2008r4.1 Xcode 2.4.1 OS X 10.4.11


Top
 Profile  
Reply with quote  
 Post subject: Re: Do I Need To Call REALLockObject?
PostPosted: Mon Oct 20, 2008 12:01 pm 
Offline

Joined: Wed Sep 28, 2005 6:06 pm
Posts: 292
Quote:
When the plugin creates the object, REALnewInstance returns a locked object (right?)

Yes: this is true of every function which returns an object.

Quote:
Does the plugin need to call REALLockObject in GetFirstThing before it returns the object to RB?

Yes: you must always lock an object before returning it.

Quote:
The RB code wouldn't assume that it came locked and just unlock it after it was done would it?

Yes, it would assume that; that is how the locking scheme works. Returning an object as a function result counts as creating a reference to that object. The caller expects you to lock the object and will unlock it when it is done.

-Mars


Top
 Profile  
Reply with quote  
 Post subject: Re: Do I Need To Call REALLockObject?
PostPosted: Mon Oct 20, 2008 11:10 pm 
Offline

Joined: Wed May 10, 2006 5:16 pm
Posts: 19
Location: Lawrenceville, NJ
Thanks for the clarification. That helped me fix a leetle bug :)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group