Advertisement Jump to content
Sign in to follow this  
Rain Dog

Application defined structs

This topic is 4918 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.

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!