Sign in to follow this  
Rain Dog

Application defined structs

Recommended Posts

Rain Dog    136
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
WitchLord    4677
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this