Legacy GM var keyword

M

mikahon

Guest
In this kind of situation ...
Code:
 - Step event -

for (var i = 0; i < 99; i++)
{
    //Do something
}
... is it bad to use the var keyword ?

I don't need to keep the i counter in memory, but since it's in the Step event, isn't using var every step taking more time since you basically declare it again and again ?
 
Last edited by a moderator:

zbox

Member
GMC Elder
GC = garbage collection

If youre talking about for datastructures? There isn't any you have to do it manually. Otherwise this stuff is just really standard variable scoping :)
 

rIKmAN

Member
Yeah sorry GC = Garbage Collection / Garbage Collector.

In other languages I've used it was managed automatically and doing something like OP in declaring a var repeatedly in an OnUpdate / Step event could cause stuttering for a frame or two when the GC finally kicked in at some point down the line.

In some cases it was be better to declare a normal variable and use that each frame rather than repeatedly redeclare a new local var.

Just wanted to check how it worked in GM.
 
X

xleonhart

Guest
I think the local variables are allocated to the Stack, not to the Heap. Then GC will not affect it :)
 
Top