Uploaded by Mahmoud El-khalil

cs2301 written assignment

advertisement
Memory process
Memory management in a computer system• It is all about representing data elements within the memory.
• Memory is managed by allocation and deallocation.
• The memory is managed by different programs by either dividing or
partitioning them into different units for specific tasks.
• When the memory allocated for the program is no longer needed the memory
is freed or deallocated.
For example• The concept of a new keyword in the C++ example is a way to allocate
memory and free is used to deallocate them.
The memory comprises different segments like a stack, heap, data segment, and
code segment.
Memory management within the computer system depends solely on hardware as
well as operating system capabilities.
StacksIt is used for storing local variables created within the functions. It can be command
line arguments as well. It provides the memory for function arguments, the return
value, and the local variables. In case of recursion, it also stores multiple frames for
the same function.
•
•
It follows the principle of last in and first out.
Whenever a function is called it is given memory within the stack.
•
•
•
As soon as the function finishes execution, the function gets popped from
the stack.
Each subsequent call to different functions is stacked one over the
other. This makes the removal of the last inserted element to be removed
first possible.
The push and pop are the two operations supported here.
Heap MemoryIt is used for management of the dynamic memory. It removes the drawback stack
of any data allocated is removed when the function returns.
•
•
•
•
The memory for the program can be allocated anywhere within the heap.
As soon as the program finishes its execution, the memory is freed. This
deallocation can happen in any order, since it is not specific about the order,
unlike stack.
The memory allocated for the program is the very first efficiently large
enough memory block to manage the required memory request.
Here the memory formed is a contiguous one.
Working of virtual memoryIt is the approach used within the operating system. To compensate for the
shortage of physical memory, the data is transferred from the main memory to the
disk.
Download