Memory Management Flashcards

1
Q

What are the four areas of memory?

A

Code segment, data segment, function call stack, heap

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

What does the code segment contain?

A

Program instructions, addresses of functions

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

What does the data segment contain?

A

Global variables, static variables, literals

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

What is the function call stack used for?

A

Managing the order of function calls, storing local variables (including parameters)

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

What is the heap?

A

Part of the data segment, it stores all dynamically allocated memory

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

What is a stack?

A

A data structure analogous to a stack of dishes. Data is pushed in and popped out in a last-in, first-out fashion.

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

What is the function call stack?

A

It manages the function-call-and-return mechanism

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

What does the function call stack contain?

A

Automatic variables, return address of the next instruction in the calling function

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

What is control flow?

A

The order in which instructions are executed

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

How does control flow work?

A

Begin at first instruction in main() function, continue sequentially to next instruction, when a function is called, control transfers to the first instruction of that function, and when returned, control is transferred back to the calling function

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

How does the function-call-and-return mechanism work?

A

When a function is called, a new stack frame is created and pushed onto the function call stack. The top frame always belongs to the function currently executing. When a called function returns, its stack frame is popped off, memory from local variables freed up, and control transferred back to the calling function.

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

What does a stack frame contain?

A

Automatic variables (parameters and locals), and the address of the next instruction in the calling function, where control will be transferred after the called function ends.

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

What is the heap?

A

A portion of program memory used for dynamically allocated memory

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

What is static allocation?

A

Memory allocation that happens at compile-time. Memory is allocated statically simply by declaring variables.

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

What is dynamic allocation?

A

Memory allocation that happens at run-time. In C we do it by using the malloc() library function

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

What is a common problem with dynamically allocated memory?

A

Memory leaks

17
Q

What is a memory leak?

A

Block of dynamically allocated memory that is never deallocated, which can eventually cause a crash. Done using free() function

18
Q

What is memory allocation?

A

Reserving bytes in memory