

While Heap segment is the one which is used for dynamic memory allocation, this is another more complex topic out of this post’s scope. This is the topic of this post, you’ll know more detailed in the following sections. Simply speaking, Stack is the memory area which is used by each process to store the local variables, passed arguments and other information when a function is called. And the most two critical sections are: Stack and Heap. There are some awesome posts on the internet about memory layout. And memory layout use diagrams to help you understand the concept of process virtual address space easily. The memory assigned to a process is called process’s virtual address space( short for VAS). In a more specify way, some memory (virtual memory) is allocated to each process in execution for its usage by operating system. When a program executes then it starts loading into memory and become a live entity. When you create a program, it is just some Bytes of data which is stored in the disk. Stack Memory Management Basic Memory Layout of Processīefore we talk about Stack memory management, it’s necessary to understand memory layout of a process.
#STACK VS HEAP PERSISTENT CODE#
To understand the concepts and machanisms deeply, a few assembly code will be shown in this post, you don’t have to know assembly lauguage as an expert for reading this post, I will add comments for these assembly codes to make explain what’s their functionalities. Stack frame of function call and return mechanism.CPU register related to stack memory management.

I will explain the mechanism in detail with examples and diagrams.īriefly speaking, the contents of this post is: Especially understand how the stack frame of function call works, which’s the most important part of stack memory. In this post, I want to share something interesting I learned about stack memory management. This post can’t cover everything related to it.

First I have to admit that memory management is a big( and important) topic in operating system.
