I have been trying to learn about the memory management in C# and it is a very interesting topic. I made one simple code which is as follows:
using System; public class MyClass { public void Go() { int x = 5; AddFive(x); } public int AddFive(int pValue) { pValue += 5; Console.WriteLine(pValue); return pValue; } public static void Main(String[] args) { MyClass mc1 = new MyClass(); mc1.Go(); Console.ReadLine(); } }
I was reading an article from this website about the memory management by Matthew Cochran and it had the following statements:
When we make a method call here's what happens:
- Space is allocated for information needed for the execution of our method on the stack (called a Stack Frame). This includes the calling address (a pointer) which is basically a GOTO instruction so when the thread finishes running our method it knows where to go back to in order to continue execution.
- Our method parameters are copied over. This is what we want to look at more closely.
- Control is passed to the JIT'ted method and the thread starts executing code. Hence, we have another method represented by a stack frame on the "call stack".
Please explain me all the three points(especially the first and the third point) in a very simple way. I am a beginner and i want to know what happens when we execute a method..... Thanks in advance!!!