Memory Management Flashcards
What is layout of x86 / x86_74 memory structure (top to bottom)
- Code/text segment
- Initialised data segment
- Uninitialized data segment
- Heap / Stack
What is the in the text/code segment?
Binary instruction set of the program (what the program does). Read only.
What is in the initialised data segment?
- Where you store Global + static variables with non-zero values. Values are copied from the text/code segment
- Initiated before program execution
What is in the Uninitialized data segment (.bss)?
Stores Global and static variables initialised to zero or not explicitly initialised in our code. Initiated before program execution.
What does the stack store?
Variables created and removed through execution. First in last out.
What does a stack pointer provide?
It points to the next available memory address.
What happens to the stack pointer when a variable is created?
When a variable is created, the stack pointer increases by the size of variable in bytes.
What happens to the stack when a variable is removed?
The stack pointer is decremented by the size of variables in bytes. The values aren’t cleared.
What happens to the stack when you enter a function?
When you enter a function it pushes a stack frame onto the stack.
What does a stack frame for functions contain?
A stack frame contains the return address where the function was called from, and any argument variables.
What happens to the stack when a function declares a variable?
The variable is pushed onto the stack during the execution of the function call (length of the scope).
What order are local variables removed from the stack on return of a function?
On returning from a function, local variables are removed in reverse order of their creation. (Push onto the top, pop off the top)
How big is the stack?
Size of the stack is fixed and known at execution time
When do stack overflows occur?
- If we make a large number of variables or large variables within a function
- Recursively call a function too many times.
What is the Heap?
Memory dynamically allocated by the programmer.