Advertisement

AngelScript memory management

Started by March 21, 2016 06:59 PM
1 comment, last by Felps 8 years, 8 months ago

This would be a simple question for the author to answer, and probably anyone who's embeded AS before... I googled, but admit I didn't search this forum specifically for the answer...

If I have an object, which stores a static list of pointers to all instances of itself, if I register the type to AngelScript for users to isntantiate, will the pointer always be valid? IE: As long as the object is alive in the script, will the pointer point to the actual script object? Or is there a chance that AS will move the data?

In other words, to properly track the instance, will I have to register a move constructor?

What I'm doing is making simple little interface objects that abstract away keeping track of indexes, and other complications of my underlying API, and I want it to be as simple as changing an x/y variable on the instance, so I'll need to go through every instance of the interface class and read its data into my sprites, for example, before drawing their positions. The simpler way to do this would be to make everything a function, but instance.setX(number); is awfully verbose for what should be instance.x = number;

I'm not entirely sure what you're asking with regards to memory usage. A lot of it depends on how you register your types to the engine. Angelscript won't move/reallocate instances of reference-counted objects by itself though, if that's what you're asking.

You should also note that you can register methods get_x()/set_x() and they will automatically be called as accessors when you use instance.x as a property.

Advertisement

This is exactly the information I needed!

I was even thinking about making special classes with overloaded assignment operators >.>

I'm not entirely sure what you're asking with regards to memory usage. A lot of it depends on how you register your types to the engine. Angelscript won't move/reallocate instances of reference-counted objects by itself though, if that's what you're asking.

You should also note that you can register methods get_x()/set_x() and they will automatically be called as accessors when you use instance.x as a property.

The set_x() method fits my needs perfectly, and eliminates a loop from the first method I thought of...

This topic is closed to new replies.

Advertisement