OPS Written Assignment Unit 5

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Written Assignment Unit 5

University of the People

CS 2301: Operating Systems 1

Shozab Khurshid (Instructor)


Below is a simplified diagram illustrating how memory and virtual memory addressing work,

specifically in the context of stacks and heaps:

-------------------------------------------------------------
| Virtual Memory |
-------------------------------------------------------------
| Stack Area |
| (Stores function calls, local variables, and parameters) |
| |
| |
| |
| |
-------------------------------------------------------------
| Heap Area |
| (Dynamic memory allocation for objects and data structures)|
| |
| |
| |
| |
| |
-------------------------------------------------------------
| Code/Data Area |
| (Stores program instructions and global variables) |
Explanation:

• Virtual Memory: This represents the entire memory space accessible by the program.

It consists of the stack, heap, and code/data areas.

• Stack Area: The stack is used for storing function calls, local variables, and

parameters. Each time a function is called, a new stack frame is created and pushed

onto the stack. When the function returns, its stack frame is popped off the stack.

(Geeks for geeks 2023).

• Heap Area: The heap is used for dynamic memory allocation, allowing objects and

data structures to be allocated and deallocated as needed during program execution.

Memory in the heap is typically managed by the programmer using functions like

malloc() and free() in languages like C and C++. (Walls, n.d.).

• Code/Data Area: This section stores program instructions (code) and global variables.

It also includes static variables that are initialized at compile time.

In terms of memory addressing:

• Each area of memory is assigned a range of virtual addresses.

• The operating system is responsible for mapping these virtual addresses to physical

addresses in RAM.

• Virtual memory management techniques such as paging and segmentation are used to

efficiently manage memory allocation and ensure that processes can access the

memory they need without conflicting with other processes.

References:
Geeks for geeks. (20 Mar, 2023). Function Call Stack in C. Retrieved from

https://www.geeksforgeeks.org/function-call-stack-in-c/

Walls, C. (n.d.). Dynamic Memory Allocation and Fragmentation in C and C++. Design

reuse. https://www.design-reuse.com/articles/25090/dynamic-memory-allocation-

fragmentation-c.html

You might also like