Memory Management

 Memory management is the process of controlling and coordinating computer memory

It is assigning in portions called blocks to various running programs to optimize overall system performance. 


Memory management resides in hardware, in the OS (operating system), and in programs and applications.



When a software runs on a target Operating system on a computer it needs access to the computer's (main memory) RAM(Random-access memory) to:

  • load its own bytecode that needs to be executed

  • store the data values and data structures used by the program that is executed

  • load any run-time systems that are required for the program to execute

When a software program uses memory there are two regions of memory they use, apart from the space used to load the bytecode, Stack and Heap memory.


Stack:
  • Stack: The stack is used for static memory allocation and as the name suggests it is a last in first out(LIFO) stack

  • But this means any data that is stored on the stack has to be finite and static(The size of the data is known at compile-time).

  • Memory management of the stack is simple and straightforward and is done by the OS.

  • Typical data that are stored on stack are local variables(value types or primitives, primitive constants), pointers and function frames.

Heap:
  • Heap is used for dynamic memory allocation and unlike stack, the program needs to look up the data in heap using pointers .

  • It is slower than stack as the process of looking up data is more involved but it can store more data than the stack.

  • This means data with dynamic size can be stored here.

  • Heap is shared among threads of an application.

  • Typical data that are stored on the heap are global variables, reference types like objects, strings, maps, and other complex data structures.

  • when we talk about memory management we are mostly talking about managing the Heap memory.


Post a Comment

0 Comments