Memory management
Page content
- Data processing and concurrent processing
Memory allocation
Memory allocationis the assignment of an empty block of space in physical or virtual memory.
1. Static memory allocation
-
The program is allocated memory at compile time.
-
Stackis used for implementing static allocation.- Here memory cannot be reused.
static int a=10;# C/C++
-
Methods and variables are created in
Stackmemory.- A stack frame is created whenever methods and variables are created.
- These frames are destroyed automatically whenever methods are returned.
- A stack frame is created whenever methods and variables are created.
2. Dynamic memory allocation
-
The program is allocated memory at runtime.
-
Heapis used for implementing dynamic allocation.- Here memory can be freed and reused when not required.
int *p; p=new int# C/C++
-
Dynamic memory allocation underlies Python memory management because everything in python is an object.
-
Objects and instance variables are created in
Heapmemory.- As soon as the variables and functions are returned, dead objects will be garbage collected.
Python memory manager
-
The raw memory allocatorinteracts with the memory manager of the OS to ensure that there’s space on the private heap.- There’s a private
heapthat contains all Python objects and data structures.
- There’s a private
-
Memory manager manages the heap on demand.
-
It has object-specific allocators.
-
If the objects get destroyed, it fills this space with a new object of the same size.
-
It manages chunks of memory called
blocks.- A collection of
blocksmakes up thepool.Pools are created onArenas.
- A collection of