Dynamic Memory Management in C++

Rishabh Agarwal
4 min readMar 22, 2023

Dynamic Memory Management is the process of allocating and deallocating blocks of memory during runtime. It is a critical aspect of programming in C and C++, where memory allocation is done dynamically.

In this article, we will take an in-depth look at dynamic memory management in C-based languages and explore the differences between dynamic memory allocation and deallocation in C and C++.

Understanding Memory

When a program is loaded into memory, it is organised into four areas of memory, called segments : the text segment, the data segment, the stack segment, and the heap segment.

Memory Layout

The text segment (also known as the code segment) contains the program’s compiled code. This is the machine language representation of the program steps to be performed, which includes all user and system provided functions.

The data segment is further sub-divided into two segments: Initialised and Uninitialised. All the global, constant and static data is kept in Initialised Data Segment. All the uninitialised data is stored in the Uninitialised Data Segment.

--

--

Rishabh Agarwal

Software Developer 2 @ Schrödinger | IIT CSE Graduate - Writes about Software Engineering!