Short Note in terms of compare Stack and Heap for Backend developers.
|Type of data structures||A stack is a linear data structure.||Heap is a hierarchical data structure.|
|High-speed access||Slower compared to stack|
|Access||Local variables only (value type)||It allows you to access variables globally (ref type).|
Limit of space size
|Limit on stack size dependent on OS.||Does not have a specific limit on memory size.|
|Resize||Variables cannot be resized||Variables can be resized.|
|Memory Allocation||Memory is allocated in a contiguous block.||Memory is allocated in any random order.|
|Shortage of memory||Memory fragmentation, Memory Leak|
Bold text is important note.