Storage Allocation Flashcards

1
Q

what is storage allocation

A

is the assignment of specific
memory locations to specific variables.

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

memory layout of a UNIX process (program)

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

Stack

A

local variables and function parameters are stored here - Automatic variables
the stack grows from higher to
lower memory addresses and is usually quite limited in size

Stacks have a small size because of multithreaded processes, stack space is shared by all threads, and it is rare for a process to legitimately need a larger stack

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

Heap

A

When: programmers may explicitly allocate memory at runtime

Property: grows from smaller addresses to larger addresses and is much larger than the stack.

Storage that is allocated using the dynamic
allocation method is allocated from the heap space.

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

uninit.data, init.data

A

what:Statically allocated storage lives in these memory areas

init. data memory space: stores statically
allocated variables that are initialized in the program code.

uninit.data memory space :stores statically allocated variables that are not initialized by the
program.

program’s global variables are all statically allocated and stored
in init.data if they are initialized when defined, or in uninit.data if they are not initialized

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

Text

A

contains the program’s code.

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

Static Allocation

A

when: performed by the compiler before the program runs.

statically-allocated variable resides either in the uninit.data or the init.data sections of process memory,

specified by including the keyword static before the variable declaration or definition.

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

Static Allocation

A

variable defined using static allocation has only one copy of the variable during the entire execution of the program, even if the variable is a local variable.

Global variables are statically-allocated by default.

local variable statically defined do not get duplicated with each call to that function because it isn’t stored in the stack frame. Instead there is only copy of the local variable
for all calls to that function.

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

global variables that statically allocated

A

global variables are starically allocated by default

but if it has the word static it works differently.
without static keyword: it is visible (if it is declared) to all of the .c files compiled together to form the program.

with static keyword: A global variable defined with the static keyword has a scope of only the .c file in which it is defined. It is
completely invisible to other .c files compiled into the same program even if it is declared (an error
will occur during compilation if a file declares a static variable defined in another file).

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

Statically-allocated variables that are initialized at the same time as it is defined

A

Initialization value must be known at compile-time
it must be a literal or another form of constant value.

the initializer cannot be the value of a non-statically allocated variable.

However, it is perfectly fine to assign the value of any variable to the statically allocated variable at a later time, as long as it is done separately, after the definition

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

Automatic allocation

A

By default, all non-global variables use automatic allocation
This includes all function parameters, and all local variables within functions.

do not exist until program execution enters their scope

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

Automatic allocation

A

By default, all non-global variables use automatic allocation
This includes all function parameters, and all local variables within functions.

do not exist until program execution enters their scope

Automatic variable definitions are not initialized by default. You must initialize the value of a local
variable, otherwise it will be random bits

When program execution leaves the scope of a variable, it ceases to exist because it gets popped
off of the stack.

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

Dynamic Allocation

A

is a manual process that must be explicitly coded by the programmer

allocates memory for a variable from the heap area.

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

Allocation Time and deallocation

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