Dynamic Programming Flashcards

1
Q

Memory in C

A

Divided into 5 segments

  1. Uninitialized data
  2. Initialized data
  3. Heap
  4. Stack
  5. Code
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Stack

A

Used to store automatics and activation records for functions
-located at the top of writable memory (grows downwards)

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

Heap

A

Stores explicitly requested memory which must be dynamically allocated (grows upwards)

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

Stack frame

A

Every time a function call is made a new stack frame is created and memory allocated for variables to be used by the function
- if stack and heap continue to grow, all memory available to the process will be exhausted and out of memory error will occur

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

Reason for dynamic memory

A

If we don’t know how much memory will be used.

Then it would be inefficient to allocate as much memory as possible

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

Heap memory

A

For dynamic allocation when size of not known until run-time

- malloc()

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

Stack memory

A

When size is known at compile time

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

Anonymous variables

A

Memory addresses in the heap, do not have names

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

Malloc()

A
  • allocate dynamic memory
  • returns memory addresses and takes number of bytes of heap memory to be allocated
  • must always check the value returned by malloc()
  • have to use typecasting with malloc()
  • need #include
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Free()

A
  • use to return heap memory no longer needed back to the heap pool
  • takes a pointer to the allocated block of memory
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Memory leaks

A
  • occurs when heap memory is constantly allocated but is not freed
  • systems with automatic garbage collection almost never have memory leaks but it is not in the control of the programmer
How well did you know this?
1
Not at all
2
3
4
5
Perfectly