Created: 2024-01-28 09:25
Status: #concept
Subject: Programming
Tags: Reference Pass-by-Reference Stack Data Structure
Execution Stack
A section of computer memory dedicated to holding non-Reference types.
Value Types
"Value types" are stored in the CPU's execution stack inside stack frames (or activation records), once the Scope of that value is destroyed, the stack frame is deallocated from Memory.
- when there are too many stack frames, due to Recursion, it will create a Stack Overflow and break the program due to lacking memory.
References Types
These types are typically Pointers to Objects and their Memory Address values are stored in the stack, which point to regions in memory called the Memory Heap.
- the heap is shared across many applications of the Operating System at the same time.
- once finished they are garbage collected or deallocated.
- they can point to nothing, or
NULL
.
int[] data;
data = new int[3];
- The
new
keyword informs .NET Runtime to create an instance ofint
C# Array, and then coordinate with the operating system to store the array sized for threeint
values in memory.