RD21: Memory Allocation II

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

1/30

flashcard set

Earn XP

Description and Tags

Allocation Strategies, Alocation and Splitting, Freeing and Coalescing, Explicit Free List Intro

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

31 Terms

1
New cards

What are the three allocation strategies for an allocation request (when searching for a suitable free block)?

First fit, Next fit, and Best fit.

2
New cards

What is the “First fit” allocation strategy?

Searches the list from the beginning and returns the first free block that is large enough.

3
New cards

What is the “Next fit” allocation strategy?

Searches the list starting from where the last search finished and returns the first free block that is large enough (wrapping around at the end of the heap).

4
New cards

What is the “Best fit” allocation strategy?

Searches through the whole list and returns the free block that is “best” - large enough to fulfill the request, but minimal external fragmentation.

5
New cards

What’s the tradeoff of the allocation strategies?

Strategies that are completed quickly have worse fragmentation and vice versa.

6
New cards

Example of the allocation strategies:

knowt flashcard image
7
New cards
<p>Where would&nbsp;“First fit” allocate?</p>

Where would “First fit” allocate?

First fit would allocate after B1, since we search from the start of the heap.

8
New cards
<p>Where would “Next fit” allocate?</p>

Where would “Next fit” allocate?

Next fit would allocate after B5, since we search from the end of B5, the last fulfilled request.

9
New cards
<p>Where would&nbsp;“Best fit” allocate?</p>

Where would “Best fit” allocate?

Best fit would allocate after B3, since the available space is the closest fit to the requested payload size.

10
New cards

What’s the first step to fulfilling an allocation request?

  1. Compute the necessary block size, based on the payload, metadata, and padding for alignment.

11
New cards

What’s the second step to fulfilling an allocation request?

Search for a suitable free block using the allocator’s allocation strategy. If found, continue. If not found, return NULL.

12
New cards

What’s the third step to fulfilling an allocation request?

Compare the necessary block size against the size of the chosen block. If equal, continue. If not, split off the excess and convert it into a new free block.

13
New cards

What’s the fourth step to fulfilling an allocation request?

Allocate the block and return the address of the beginning of the payload.

14
New cards

What are the two ways the allocator’s chosen alignment affects heap blocks?

  1. The address of the beginning of the payload must be a multiple of the alignment size.

  2. The total size of the block will be padded out to be a multiple of the alignment size.

15
New cards

What is the minimum block size determined by?

The larger requirements between allocated and free blocks in our allocator implementation.

16
New cards

How does minimum block size relate to the computation of the necessary block size (step 1) and splitting (step 3)?

  1. The computed necessary block size will be padded out to the minimum block size.

  1. If the remaining free space after splitting is less than the minimum block size, then it’s included as padding in the allocated block.

17
New cards

An example of Implicit Free List Block Size:

knowt flashcard image
18
New cards

Referring to the Implicit Free List example, if the request was instead malloc(1) and the same free block was chosen, what would the header of the newly-allocated block be?

“16|1. The minimum block size is 16 bytes, so it will split the free block into an allocated block of size 16 followed by a free block of size 32.”


19
New cards

How can you simply free an allocated block?

Flip its is-allocated flag.

20
New cards

What’s a potential issue with flipping the is-allocated flag?

The block becomes unusable due to external fragmentation.

<p>The block becomes unusable due to external fragmentation.</p>
21
New cards

What is coalescing?

Coalescing is combining neighboring free blocks into a single, larger free block.

22
New cards

When do we coalesce?

We coalesce when we free an allocated block in order to maximize the allocator’s ability to fulfill future allocation requests.

23
New cards

Example of coalescing:

knowt flashcard image
24
New cards

What is a footer block?

A copy of the header information except at the end of hte block so it can be read by the following block.

25
New cards

What do footer blocks allow us to do?

Footer blocks allows backward coalescing and traversal of the heap blocks in the reverse direction.

26
New cards

What are the header and footer collectively known as?

The boundary tags.

27
New cards

How many possible scenarios are there when freeing a block? Why?

4 possible scenarios based on whether the preceding and following blocks are free or allocated.

28
New cards

Examples of the 4 cases when freeing a block:

knowt flashcard image
29
New cards

For an implicit free list with 16-byte alignment and 8-byte boundary tags (8 bytes each for the header and footer), what is the minimum block size (in bytes)?

“32. We need 16 bytes for the boundary tags, but a 0-byte payload is not practical, so we need more space. Since the alignment requirement is 16 bytes, we need pad out to the next multiple of 16, which is 32 bytes.”

30
New cards

What does an explicit free list do?

An explicit free list traverses its free blocks using a doubly-linked list data structure, done by adding next and prev pointers in the free blocks.

<p>An explicit free list traverses its free blocks using a <em>doubly-linked list </em>data structure, done by adding next and prev pointers in the free blocks.</p>
31
New cards

What blocks can fulfill an allocation request?

Free blocks!