Presentation is loading. Please wait.

Presentation is loading. Please wait.

Storage Management Different-sized Items. Light blue indicates allocated items Heap Memory with Different-sized Items.

Similar presentations


Presentation on theme: "Storage Management Different-sized Items. Light blue indicates allocated items Heap Memory with Different-sized Items."— Presentation transcript:

1 Storage Management Different-sized Items

2 Light blue indicates allocated items Heap Memory with Different-sized Items

3 Light blue indicates allocated items Free some items

4 Light blue indicates allocated items Free some items Although we have 50 free bytes, we can’t satisfy a request for more than 30 bytes

5 Light blue indicates allocated items Free another item We need to recognize when two adjacent items are free. How can we recognize that two adjacent items are free? Suppose all free nodes are on a free linked list. Since the free bytes aren’t being used, they easily can be made “free” nodes. We could follow the free list and see if any node’s address + size is the address of the recent free node. Free List Head

6 Light blue indicates allocated items Free another item Combine them. Free List Head

7 Light blue indicates allocated items Free another item Combine them. Free List Head

8 Of course, the item being freed could precede a free item already in the list What if there is a free item after a newly freed item?

9 Free List Head Of course, the item being freed could precede a free item already in the list We can check the next item to see if its indicator indicates free. We also need to update the free list. Do we really need to search the entire list? What could we change to avoid that search? What if there is a free item after a newly freed item?

10 Free List Head The newly freed item might be between two already free items. What if the newly freed item is surrounded by free items?

11 Free List Head The newly freed item might be between two already free items. So, we need to always check before and after it. What if the newly freed item is surrounded by free items?

12 Free List Head Suppose we need to allocate an item of 40 bytes, where should we place it? Algorithms: First Fit - scan the free item list looking for the first free item of N or more bytes. Allocate N bytes from the free item and the remainder might be free space. Best Fit - scan the free item list looking for the first free item with the minimum number of bytes >= N. How can we optimize this search? Which free item to use when allocating?

13 Light blue indicates allocated items What happens if we need to allocate a 48 byte item? Free List Head Can there be an issue with the left over free space?

14 Light blue indicates allocated items What happens if we need to allocate a 48 byte item? The free portion is too small for the standard free node format. What should we do? Free List Head ? Can there be an issue with the left over free space?


Download ppt "Storage Management Different-sized Items. Light blue indicates allocated items Heap Memory with Different-sized Items."

Similar presentations


Ads by Google