A process can have many threads. Once created, a 1 MB stack is allocated to the thread. Stack-allocated memory is used to pass parameters to methods and store local variables defined within the methods.
Stack (stack) - this is the memory area in the address space.
Stack (stack) grows from the bottom up.
Each new element is placed at the very top.
When deleting: the item that is at the very top will be deleted first.
Stack (stack) uses an algorithm "the last one entered - first came out" (last-in-first-out) LIFO
Stack (stack) used for:
• pass parameters to methods
• storing local variables inside a method
C#
class Program
{
static void Main(string[] args)
{
Calculate(4, 7);
}
static int Calculate(int a, int b)
{
return a + b;
}
}
C#
class Program
{
static void Main(string[] args)
{
Calculate(10);
}
static int Calculate(int param1)
{
int x = 6;
int y = x + param1;
return y;
}
}
When you call this method
Calculate values will be placed in the stack
t,
x,
y and
z. They are defined in the context of this method. When the method completes, all these variables are destroyed and the memory in the stack is cleared.
And if the parameter or variable of the method represents
value type, the stack will store the value of that parameter or variable. For example, in this case, variables and a method parameter
Calculate Represent
value type int, therefore they will be stored in the stack
numeric values.