Jump to content
  • Advertisement
Sign in to follow this  
Rain Dog

Application defined structs

This topic is 4852 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

I've always wondered: Do structs need to have asBEHAVE_CONSTRUCT and asBEHAVE_DESTRUCT registered for structures in order for them to be declared in script? Also, what about references? do they need addref/release behaviours also?

Share this post


Link to post
Share on other sites
Advertisement
If a type is registered without the asBEHAVE_CONSTRUCT, the script engine will allocate the memory, but will not initialize it. Thus, any pointers, complex members, or the virtual function table, will be invalid. If the C++ type doesn't contain any of these, then asBEHAVE_CONSTRUCT is not necessary.

Likewise, if asBEHAVE_DESTRUCT is not registered then the destructor will never be called by the script engine. It will still free the memory, but any pointers or complex members in the structure will not be properlies treated. If the asBEHAVE_RELEASE behaviour is registered, then the memory will be freed by that behaviour, thus the library will never call any registered destructor.

Any type that do not register the asBEHAVE_ADDREF/asBEHAVE_RELEASE behaviours can still be used by the script engine, but the types won't allow object handles to be used.

Regards,
Andreas

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!