Large classes / efficiency

Started by
1 comment, last by Tylon 18 years, 4 months ago
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
Advertisement
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.

Regards,
Andreas


AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

okay, thanks.

This topic is closed to new replies.

Advertisement