Sign in to follow this  

Large classes / efficiency

Recommended Posts

Tylon    181
I have exposed a class to angelscript which is relatively big (about 512bytes on the stack, ie sizeof(x) returns 512, it creates no resources on the heap however; no overloaded assignment operator). These objects will be passed around functions quite frequently, so I clearly would want to avoid copying. After reading a few posts here, I was getting the feeling even with reference parameters set to &in, there is copying being done. Or is there? variables of this object type will be passed to angelscript functions as well as c++ functions exposed to angelscript. If I specify the c++ functions to take references to that object type (and do &in for their parameters when binding), and the angelscript functions to take handles to that type, can I be guaranteed that there will be no copying done for that object at any point? Copying 512 bytes several times every frame would be quite costly overall. Thanks

Share this post

Link to post
Share on other sites
WitchLord    4677
For large objects like these I suggest that you register the behaviours ADDREF and RELEASE so that you can pass the objects around with object handles (ref counted pointers) instead. If your application uses it's own memory management routines for these objects, then you could register the ADDREF and RELEASE functions as dummy functions that don't do anything.

I'm currently in the process of changing the way AngelScript handles parameter references. The new way will avoid copying the objects, but will instead rely on object handles to guarantee that the references are valid at all times. This unfortunately means that only objects that support object handles can be passed by reference to functions.

With a compile time flag (e.g. asALLOW_UNSAFE_REFERENCES) AngelScript will allow parameter references of any type. In this mode however, it may be possible to write scripts that access invalid pointers, possibly crashing the application, or even exploiting buffer overruns to access the users system.

In addition to the parameter references, I will also allow what I call 'output parameters'. These are what AngelScript currently calls '&out'. This type of parameters will be available for all types, including primitive values.


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