Developed in Unity.
I started game development from WolfRPGEditor, so I'd like to make a program that flows from top to bottom as much as possible.
I'm thinking of preparing a coroutine for every class and calling it in the scene manager that exists in the scene, but
Is it possible to create a singleton instance and call another class method to be called?
public class Test
{
public static IEnumerator Main ()
{
// Process here
yield break;
}
}
I am worried about what I can call and use like yield return Test.Main ();
The reason I'm worried is that I read that static variables eat up memory when running a program.
However, there was nothing written about the detailed behavior of static methods, so
I also want to know how a static method allocates a memory area during program execution.
Does every local variable in the method eat memory?
Or does it seem like a method reference is passed to memory and only one memory area is needed?
Does it become heavy if there are too many static items (variables, methods, classes, etc.)?
I eat but eat about 1000 static methods.
The first question may be incomplete, but thank you.
-
Answer # 1
-
Answer # 2
Which should I use a static method or a singleton?
If you're only worried about the amount of memory used, it's the same or error range.
I think that the number of singleton objects + instance methods is slightly more than the static methods. -
Answer # 3
Static variables eat memory when running programs
That's wrong in the first place
Related articles
- how should i manage the method for issuing queries to db in c #?
- i want to color-code method names etc on visual studio 2017 c # text editor
- c # - is it impossible to apply the method break;at the caller?
- c # - what does the error "argumentexception: method return type is incompatible" mean?
- call static method on command when running php in command prompt
- java - i want to call a static method with a method reference
- Java static generic use method instance analysis
- Java singleton mode implementation method
- dart - what a singleton is better than a static uncle
- java - kod-i want to know what to do when an error occurs in a method that should not have been written
- c # - why doesn't it work without static?
- c # - i can't make a singleton
- Method of Go compiling 32-bit GNU static link library
- c # - i want to change only the type of the arguments with the same method contents
- c # - operations on static members and constructors in non-static classes
- c # - whether the controlinvoke method guarantees the order by the operation equivalent to threadmemorybarrier
- c # - about the naming of the method that checks the input
- c # i want to pass a value to another method in the same class
- c # - i want to call a method of another script in unity, but it doesn't work
- c # - what kind of method is there to clarify the cause of the exe file, which is neither good nor bad?
- c # - player production in unity (shooting game)
- c # - maintain current speed with vector3
- c # - i want to get the bool in scriptableobject
- c # - i want to slowly rotate the model to a fixed angle when the flag is set, and slowly return it to the original angle when t
- c # - only part of the color of the image cannot be referenced
- c # - error in nav mesh agent
- c # - unity online ranking i want to implement with time type
- c # - [unity] i want to make the camera follow the player in photon, but if there are multiple players, it will not follow
- c # - i want to call a method of another script in unity, but it doesn't work
- c # - i want to stop the score due to a player collision
Hello.
A normal variable and a static variable are allocated as a variable area and a variable management area.
Rather, ordinary variables should consume slightly more memory.
There is almost no difference in the memory area allocation method for non-static methods and static methods.
These differences are in principle only whether or not the pointer to this object = this is received as a (hidden) argument.
Method = program. Whether a method is static or non-static, only one set of areas is recorded. You may feel that ordinary (= non-static) methods are copied to the code (program) of the method for the number of objects, but that is not the case. There is only one set of method code.
A method's local variables are reserved only during execution of the method.
When the method is not executed, the local variable does not consume memory. (Not secured in memory.)
If the same method is executed multiple times at the same time, such as by recursive calls or calls from multiple threads, local variables are allocated as many times as the number of multiple executions.
This is the same for both normal and static methods.
The reverse. In terms of "weight", non-static variables, methods and classes are "heavy" than those that are static. Those that are static are "static". That means it will not change during program execution. This means that resources (memory and CPU) are not consumed for the change.
However, the difference is within the error range so you don't have to worry about it. Projects that care about this difference should use C ++ instead of C #, and maybe a project that should use C or assembler.