Senior software engineer. Payments infrastructure in Go, and essays.

How Memory Allocation Works in Modern Programming?

— 2 min read

How a program looks like in RAM?

When a compiled/executable program gets loaded in memory it becomes a process and operating systems manages all relevent process information like process id, process state etc. into the Process Control Block(PCB). A typical process in memory is divided into the following major segments

Diagram of a process in memory, top to bottom: code/text segment, data segment, stack, heap

Code/Text Segment

Data Section

Stack

Heap

How memory get allocated & deallocated?

we can say that now we have three types of programming language First in which programmer has to allocate and deallocate the heap memory. Second one is which allocation will taken care by runtime and deallocation will be taken care by GC. Third one in which allocation will taken care by runtime but heap memory is freed automatically and deterministically when the owner goes out of scope so no manual or no GC.

Also on Substack: read or comment there. Get new essays by email — subscribe on Substack.