i have several instances of one object/class and i realized that this object has like 6 variants of a constructor function which are only invoked when the object is initialized. now what i don't know if these functions are stored for each instance separately? if yes, then probably i should make these functions global and change them so they give back a prepared fully constructed object. this way these functions would be in the memory once instead of 100 times.
as far as i remember in more oop-oriented languages you can decide if a function of a class is global or local in the sense that it is one for the whole class or one for each object. can you make such a differentiation with lua? and which case is happening by default?
my lack of understanding what is happening in the background goes farther of course, e.g. what if a function of the class is put on each onenterframe of each instance, then do we have 100 copies of this function in the memory or only 1? but maybe this works exactly the same way as my question above and making it an eventhandler does not change the number of functions in memory.
so probably there is an easy answer, please tell me.
Comments
well if by global methods you mean static methods, then you can store them as properties of a class, as:
Likes: zvardin
and of the two ways which is stored only once in the memory? only the static? none? both?
because actually being able to use self would be useful even in a function which is static in the above sense.
i hope my question is understandable.
Fragmenter - animated loop machine and IKONOMIKON - the memory game
finally i put as much as i could outside of the class so that i save even the references. i doubt that it changed anything performance-wise, but whatever.
maybe @atilim could give the final 'official' answer in this discussion about static and normal functions of classes, how they are stored/referenced per instance?
Fragmenter - animated loop machine and IKONOMIKON - the memory game
Test.lua:
Uploading finished.
function: 07127F30 function: 07127F30 function: 07127F30
true
function: 07127F50 function: 07127F50 function: 07127F50
true