Digging deeep into python : Part 5 | Memory internals

Python memory internals..


Python has a memory manager and a private heap to store python objects and data structures. This python memory manager has different components to deal with dynamic memory allocation, sharing, segmentation, preallocation or caching. 
At the lowest level raw memory allocator ensures whether there is enough room for variables in private heap by interacting with memory manager of OS. On top of the raw memory allocator there are object specific allocators for distinct python objects which works on the same heap. Rather than string, tuples or dictionaries, for integer the object specific allocator implies some policies to ensure dynamic storage requirements and speed/space trade offs. 
In python all these things are done by the interpreter itself, user has no role in it.
If we try to use the functions exported from C such as malloc(), calloc(), realloc() and free() to work on python private heap you will not get any output that you want. These C functions and python memory manager implement different algorithms and works on different heap😇. 
So these are the basic internals of python. You can read more by referring this link


Post a Comment

Popular Posts