Inspecting some of the bytecode output from script class constructors one thing I noticed was that application POD classes were being allocated on the heap in their own little chunks of memory. This was mainly an issue for small things like 2d/3d vectors, rectangles, etc. The worst offender of it all being our 'Color' class - a shortcut for representing colors as 32-bit rgba integers which was being allocated into its own heap memory and adding a 64-bit pointer to the class.

The attached patch changes the behaviour of POD application class typed members to be stored directly in the object's allocated memory block instead. It passes angelscript's test suite, and we've been using it in our project for a few weeks now.

Feel free to use/alter if you're interested in using it.

Two small miscellaneous things that I'm going to shoehorn into this thread:

The test suite needs C++11 to compile, so the makefile needs to tell gcc to use it:

Also, there's a problem with the context used in ScriptObjectFactory: if script engine A calls an application function that wants to create a script object in script engine B, ScriptObjectFactory will nest into the context from engine A, creating a crash. This occurred in some of our cross-engine communication functions. We added a check to not use nesting if the active context is from a different engine, but there should probably be a way for the application to provide asIScriptEngine::CreateScriptObject() with the context to use for the call since creating contexts is expensive.