Does the position of GameObject in memory changes at any time? (When you add or remove other GameObject)
I would like to know whether the references to GameObjects are eternal?
p.s.
I am a C++ programmer, C# is new for me
Why would the reference of a game object, in a game object variable, change over time ? (Except in the case of the destruction of the game object)
I have assumed that all GameObject obects are stored in some kind of List object
(something like std::vector in c++).
Such lists have memory capacity,and if you change that capacity all objects are destroyed and their copies are placed in the newly allocated memory. (All references and pointersare are being lost in that point)
runs away faster than when I read C# code
Regarding declaring variables, I never heard such things. I think you could declare tons of variables, without problems :
var go1 : GameObject;
var go2 : GameObject;
...
var goN : GameObject;
Thanks for your help.
The phenomenon you’re referring to occurs when you store the ‘address’ (e.g. as a pointer, reference, or iterator) of an element stored in a std::vector, and then the vector reallocates; in that case, the ‘address’ becomes invalid (a pitfall that trips up C++ coders frequently).
However, the values that are stored in the vector don’t get corrupted when the vector reallocates (assuming the type in question implements sensible copy semantics). If you store pointers to objects in a vector, it doesn’t matter if they get moved around unless you’re storing references of some sort to those pointers; the pointer values themselves aren’t affected, nor are the objects they point to.
The basic semantics we’re talking about here don’t actually differ that much (on the surface at least) between the two languages. In C++, if you allocate an object dynamically using ‘new’ and acquire a pointer to it, that object isn’t going to randomly relocate and cause the pointer to become invalid. Similarly, when you create an object of a reference type using ‘new’ in C# and acquire a reference to it, that reference isn’t going to spontaneously become invalid (not that I know of at least). Remember, when you have a reference, you actually have a copy of the ‘address’ of the object stored as a value. Whether some other copy of that reference gets shuffled around in memory is of no concern to you.
So in short, unless I’m quite mistaken, you have nothing to worry about