Memory Layout Flashcards

1
Q

Text Section

A

Program Code

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

Data Section

A

Stores global and static data

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

Heap

A

Heap is an area of ram memory where dynamic memory allocation happens. It grows upwards and has holes.

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

Stack

A

Stack is where function related data is stored: local variables, saved registers, return addresses, function parameters
Grows down.

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

Is there a single text, data, heap sections for all running programs or does each program has its own sections?

A

each one has its own. The same is somewhat true for stack because stacks are never shared)

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

What do we mean by “stack is fast, heap is slow”? What exact operations on stack are faster than on heap?

A

memory allocation, that is finding chunk of unused memory of required size
stack is very fast because mem is managed automatically.

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

Where is the local object of std::vector class or std::string class is stored?

A

the object itself on stack, the pointed dynamically allocated array – on heap
vector<int> vec = {1, 2, 3, 4, 5}; // Local object</int>

// vec's metadata (size, capacity, pointer to data) is on the stack.
// The array {1, 2, 3, 4, 5} is stored on the heap.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

static array

A

int nums[100];

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

Dynamic array

A

A dynamic array is an array whose size is determined at runtime.
std::vector<int> nums;</int>

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

What is between heap and stack section?

A

unused memory chuncks happen in the middle of heap but not stack

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

What unit fits best for a usual stack size limit: kB, MB, GB

A

sually stack size limit is measured in MB, something like 8 MB to 32 MB depending on the system

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

What is stack overflow?

A

When the program tried to exceed stack size limit and the program crashes

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

What are the two common ways to overflow the stack?

A

large static arrays and deep recursion

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

What is the mechanism of stack overflow by the deep recursion?

A

Every time a function is called, a new stack frame is pushed onto the call stack.
The stack frame contains:
Local variables of the function.
Function parameters.
Return address to the caller function.

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

Be ready to look at C++ code and analyze in what sections all of its components are stored.

A

PRACTICE

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