Skip to main content
GameDev.net gamedev.net
🔒 Locked

Application defined structs

Started by Rain Dog Aug 3, 2005 at 1:09 PM 1 replies 1.2k views
Original Post
Rain Dog
Rain Dog
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?
WitchLord
WitchLord
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
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - <a href="http://www.angelcode.com/tower" rel
Rain Dog
Rain Dog
Ok, thanks, that clears things up for me now.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.