Jump to content
  • Advertisement
Sign in to follow this  
virious

asOBJ_REF without AddRef and Release?

This topic is 2496 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is it possible, to register object type as asOBJ_REF (to be able to pass pointers to script) but without AddRef() and Release() behaviours?

We are not going to create objects of this type in scripts, we just want to get handles to the objects created by our game engine and call some methods/set properties etc. on them.
We wanted to avoid additional function calls to AddRef and Release because we simply don't need it in our case.

Regards
virious

Share this post


Link to post
Share on other sites
Advertisement
You can easily use dummy functions and register them as your AddRef and Release behaviors. I use this for a global Math object that provides functions I would normally register as static member functions in C++.


class SomeGlobalScriptObject
{
void Dummy_AddRef() { /* do nothing */ }
void Dummy_Release() { /* do nothing */ }
};


Just remember that you are responsible for the object you register when you do this. There is really no way to avoid the AddRef and Release calls as the engine uses it for housecleaning, but unless you are working on something reeeeeeeally CPU sensitive (or are extremely anal about unnecessary function calls) it should be a non-issue.

Share this post


Link to post
Share on other sites
I've added the new flag asOBJ_NO_ADD_RELEASE and modified the AngelScript code.

Here is diff file (http://pastebin.com/CAMmy6qG) generated from my modifications. I was using AS revision number 1073.
I've also added and changed this:


asOBJ_NO_ADD_RELEASE = 0x20000,
asOBJ_MASK_VALID_FLAGS = 0x3FFFF,

in angelscript.h.


Now the AddRef and Release are no longer required (and called) for the object type registered as asOBJ_REF | asOBJ_NO_ADD_RELEASE.

Is this a correct solution to my problem?

Regards
virious

Share this post


Link to post
Share on other sites
I'll take a look at the changes you made. I was already thinking about adding a similar option for those who really don't want to use the addref/release behaviours.

Though I would probably call the flag asOBJ_APPMANAGED instead, since the application will have to do the memory management by itself.

Share this post


Link to post
Share on other sites

I'll take a look at the changes you made. I was already thinking about adding a similar option for those who really don't want to use the addref/release behaviours.

Though I would probably call the flag asOBJ_APPMANAGED instead, since the application will have to do the memory management by itself.


It's great to hear that. If you want, just modify my code and I think it should work for this case :).

Regards
virious

Share this post


Link to post
Share on other sites
Forgot about one thing. In case asBC_FREE: in as_context.cpp I've added:

if (!(objType->flags & asOBJ_NO_ADD_RELEASE))
before

*a = 0;
to prevent AngelScript from clearing object managed by my application.

Regards
virious

Share this post


Link to post
Share on other sites
I've added this in revision 1165.

I ended up using the name asOBJ_NOCOUNT for this support, as it was shorter and more meaningful than the other options.


Thanks,
Andreas

Share this post


Link to post
Share on other sites
Does this flag also make objects immune to garbage collecting? Btw, I think it should not be possible to create an object of such class through issuing a 'new' command in the scripts.

Share this post


Link to post
Share on other sites

I've added this in revision 1165.

I ended up using the name asOBJ_NOCOUNT for this support, as it was shorter and more meaningful than the other options.


Thanks,
Andreas

Great, I will test it :).

Share this post


Link to post
Share on other sites

Does this flag also make objects immune to garbage collecting? Btw, I think it should not be possible to create an object of such class through issuing a 'new' command in the scripts.


Sorry, I missed this question.

This new flag just mean that angelscript wont notify the application about references it holds. So in effect it puts more responsibility on the application for making the proper memory management.

You can prevent the script from creating objects by not registering the factory behaviours.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!