Unit 2b – Dynamic Memory Allocation

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall with Kai
GameKnowt Play
New
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/5

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

6 Terms

1
New cards

Primary reason:

If we want to allocate memory in a function and have it STAY ALIVE even AFTER that function ends

2
New cards

Secondary reason:

If we don't know how much memory we'll need until run-time

3
New cards

How do you allocate and free memory?

int *p = new int; // one int

int *arr = new int[n]; // array

delete p; // free one

delete[] arr; // free array

4
New cards

Where in the memory?

Lives in the Heap

5
New cards

New operator:

Allocates memory from the heap

double *dptr = new double;

int *scores = new int[n];

6
New cards

Delete:

Returns memory to heap

delete dptr;

delete [] scores;