Data and Program Representation Flashcards
How is memory seen by the program?
As an array of bytes.
What is the address range of memory in bytes?
0 - (2^64 - 1). * this is for 64 bit architecture
Is all of the address space of memory used?
No
What are the sections in memory called?
memory mappings
What are the memory mappings, in order form lowest to highest in address range.
Text, RoData, Data, BSS, Heap - Shared libs - Stack
What does the text memory section hold?
Instructions that the program runs
What does the data memory section hold?
Initialized global variables.
What does the Bss memory section hold?
Uninitialized global variables. They are
initialized to zeroes.
What does the Heap memory section hold?
Memory returned when calling malloc/new. It grows upwards.
What does the Stack memory section hold?
It stores local variables and return
addresses. It grows downwards.
What does the RoData memory section hold?
Read Only Data. String constants
Which way does the Stack grow?
The stack grows downwards.
Which was does the heap grow?
The heap grows upwards
What are Dynamic Libraries?
They are libraries shared with other processes.
What does each dynamic library have its own of?
text, data, and bss.
True or False, Each program (process) has its own view of the memory that is independent of each other.
True
True or False, If a process modifies a byte in its own address space, it will modify the address space of another process.
False
Below, where is line x stored?
Program hello.c
int a = 5; // Line x
int b[20];
int main() {
int x;
int p;
p =(int) malloc(sizeof(int));
*p = 5;
printf(“Hello cs250\n”);
}
data section
Below, where is line x stored?
Program hello.c
int a = 5;
int b[20]; // Line x
int main() {
int x;
int p;
p =(int) malloc(sizeof(int));
*p = 5;
printf(“Hello cs250\n”);
}
BSS
Below, where is line x stored?
Program hello.c
int a = 5;
int b[20];
int main() { // Line x
int x;
int p;
p =(int) malloc(sizeof(int));
*p = 5;
printf(“Hello cs250\n”);
}
Text
Below, where is line x stored?
Program hello.c
int a = 5;
int b[20];
int main() {
int x; //Line x
int p;
p =(int) malloc(sizeof(int));
*p = 5;
printf(“Hello cs250\n”);
}
Stack
Below, where is line x stored?
Program hello.c
int a = 5;
int b[20];
int main() {
int x;
int p;
p =(int) malloc(sizeof(int)); //Line x
*p = 5;
printf(“Hello cs250\n”);
}
Heap
What is a memory gap?
A space between memory sections where there is no memory mapping
What happens if a program tries to access a memory gap?
The OS will send a SEGV signal that by default kills the program and dumps a core file.