Memory management in Haxe

Hi, I am fairly new to Armory3D and the Haxe programming language and have a C#/C++ background.
I have been studying Haxe for a while and I can’t seem to find a feature that behaves like a C# struct. So for example, if I wanted a data structure to represent a point which contains x and y coordinates, that data structure must be instantiated via new, which allocates the object on the heap to be garbage collected later. This probably would not matter were objects allocated infrequently, but in one of the examples (armory_examples-master\material_baked), I found a source code:
function update() {
var mouse = Input.getMouse();
if (mouse.down()) {
object.transform.rotate(new Vec4(0, 0, 1), -mouse.movementX / 100);
which basically instantiates a new Vec4 object every frame for which the mouse button is held. In this case you could make a constant representing the point <0, 0, 1>, but in other cases it could be necessary or less messy to create a point object in the local scope but in a bigger game where there are hundreds of scripts running simultaneously, allocating new memory on the heap every frame for such trivial data structures could be a burden on the hardware. So is there a workaround for this kind of situation that I haven’t found out?
I’m curious because I know there are a few big game engines and frameworks are built with/for Haxe and I think value types are quite an important feature for a language used for game development.

There’s a thing called inline constructors in Haxe. If the rotate function and the Vec4 constructor are “inline” your sample code does not allocate.

Just add some inlines and send a pull request. Alternatively use Krom - Chakra does escape analysis.


Yes, inlining has its downsides.

@RobDangerous Is there somewhere an explaination of how Haxe manages/cleans up the heap memory for the different kinds of variables, maybe according to the target used, with tips on things like : if we can have the choice for stack-only data ? the way of returning memory to the operating system when this memory must be requested from the operating system at runtime ? the scope of data ?