Support for application types w/ custom alignment

Started by
10 comments, last by WitchLord 13 years, 7 months ago
I was attempting to add support for wrappers over Eigen types when I ran into the alignment roadblock-- is there a way for me to specify to the memory manager that I need a particular application type to reside on a specific memory alignment? While constructors may handle initialization, the Angelscript runtime actually handles the allocation itself.

I can see control over something like this being very useful, so I'm hoping there's a method I overlooked somewhere.
clb: At the end of 2012, the positions of jupiter, saturn, mercury, and deimos are aligned so as to cause a denormalized flush-to-zero bug when computing earth's gravitational force, slinging it to the sun.
Advertisement
For reference types you use the asBEHAVE_FACTORY behavior to allocate memory for a type.
Quote:Original post by SiCrane
For reference types you use the asBEHAVE_FACTORY behavior to allocate memory for a type.

The unfortunate part of this is that the objects in question are value types-- any way I can extend factories to cover situations like this?

clb: At the end of 2012, the positions of jupiter, saturn, mercury, and deimos are aligned so as to cause a denormalized flush-to-zero bug when computing earth's gravitational force, slinging it to the sun.
You will want to use the asOBJ_SCOPED reference type. This behaves like a value type in the script, but the memory allocations are handled by the application itself.

Registering a scoped reference type

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

I'm currently experimenting w/ the scoped reference type right now, but I'm not sure how this will interact with using objects of this type as class properties. Any insight?

EDIT: Said class properties would be members of a native C++ class. Specifically, things like position and orientation.
clb: At the end of 2012, the positions of jupiter, saturn, mercury, and deimos are aligned so as to cause a denormalized flush-to-zero bug when computing earth's gravitational force, slinging it to the sun.
Let me know if it doesn't work. If it doesn't work already I'll make it work.

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

Quote:Original post by WitchLord
Let me know if it doesn't work. If it doesn't work already I'll make it work.


Will do. If/while you're around, is there any documentation on the contract(s) for the factory functions? Am I responsible for calling/wrapping the appropriate type constructor in the factory or will Angelscript call any registered constructors?
clb: At the end of 2012, the positions of jupiter, saturn, mercury, and deimos are aligned so as to cause a denormalized flush-to-zero bug when computing earth's gravitational force, slinging it to the sun.
You will need to register the factory functions for the scoped type, just like for other reference types. The factory function is responsible for allocating and initializing the memory.

The scoped reference type doesn't use reference counting as it is supposed to be destroyed when the variable goes out of scope. For this reason the AddRef behaviour can't be registered for this type. The Release behaviour is still necessary though, as it is the one responsible for destroying the object and freeing the memory.

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

Progress update: The more I look into this, the more I think I may need to add some form of intrinsic support for aligned types to the language backend. From what I've been able to determine, this should actually be a (fairly) trivial extension-- I would need to add

A) Some method to specify to the runtime that the object type needs to be allocated along a certain boundary. A flag or additional integer designating which kind of alignment is required seems a good choice here. Alternately, something like RegisterAlignmentSensitiveObjectProperty() and a recursive 'alignment sensitivity' propagation check/flag might make things easier for the user. Additionally, this should be non-breaking with regards to bytecode, etc.

B) A means to guarantee that the allocated memory is on the needed boundary. Making a secondary allocation function type (something along the lines of asALIGNEDALLOCFUNC/asALIGNEDFREEFUNC and the corresponding debug logging functions) should be simple enough.

Thoughts? I'll try and put something together over the next few days and ship it to you if I end up with a sensible implementation.
clb: At the end of 2012, the positions of jupiter, saturn, mercury, and deimos are aligned so as to cause a denormalized flush-to-zero bug when computing earth's gravitational force, slinging it to the sun.
I'm interested in having this support natively, but I need to weigh this against complexity and performance impact. Especially in the support for native calling conventions. Is it even possible to pass this type by value?

Currently AngelScript doesn't allocate registered value types on the stack, but that is an optimization I plan on doing in a not too distant future. If there are special alignment requirements for a type, this may start to get complicated. Especially since the saved bytecode has to be platform independent, which means the alignment would have to be adjustable during the loading of the bytecode.

There is also the array type. Currently it also allocates the type on the heap, but in a future version it should probably allocate them in-row as well.

As I was typing this I came to think that AngelScript would probably have to have the ability to decide which value types should be allocated on the stack or on the heap. A type with special alignment requirements could always be allocated on the heap.

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

This topic is closed to new replies.

Advertisement