Run-Time Memory Flashcards

(10 cards)

1
Q

What is a virtual address space in a multi-tasking operating system?

A

Each process runs in its own isolated memory space

Each virtual address space starts at memory address zero

The operating system maps virtual memory addresses to physical memory addresses using page tables

The virtual address space is usually contiguous

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are sp and bp/fp in the context of memory management?

A

sp (stack pointer): Points to the top of the current stack

bp/fp (base/frame pointer): Points to the base of the current stack frame

Used to manage function call frames and local variables

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Describe the steps that occur during a function call in terms of stack management?

A

Push the current frame pointer onto the stack

Move the current stack pointer to the frame pointer

Subtract space needed for the function’s local data from the stack pointer

Execute the function code (local variables accessed via negative offsets from frame pointer)

On function exit, restore the previous stack and frame pointers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the key differences between the heap and the stack?

A

Stack:
Used for automatic (local) variables
Memory allocation/deallocation is automatic
Fixed size, managed by function calls

Heap:
Used for dynamic memory allocation
Manual memory management (malloc/free)
Can cause memory fragmentation
Larger and more flexible memory space

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What happens during deep recursion?

A

Each recursive call creates a new stack frame

Eventually, the stack fills up

Leads to a “too many recursions” error or stack overflow

Limited by available stack memory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How does a CPU translate virtual memory addresses?

A

Uses Memory Management Unit (MMU)

Employs Translation Lookaside Buffer (TLB)
- A cache of recently-used memory address mappings

Operating system maintains page tables for address translation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What typical information is stored in a stack frame?

A

Function parameters

Local variables

Previous frame pointer

Return address

Saved register values

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are some common heap memory allocation strategies?

A

Best Fit: Find the smallest free block that fits the request

First Fit: Allocate the first free block large enough to fit the request

Next Fit: Similar to First Fit, but starts searching from the last allocation point

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How does a recursive function appear in the stack?

A

Each recursive call creates a new stack frame

Frames are stacked on top of each other

Each frame contains its own local variables and parameters

Frames are removed as recursion unwinds

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

On a 64-bit machine, what are the key memory management registers?

A

%rsp (Register Stack Pointer): Points to the top of the stack

%rbp (Register Base/Frame Pointer): Points to the base of the current stack frame

How well did you know this?
1
Not at all
2
3
4
5
Perfectly