11.07.2015 Views

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Sec. 12.3 Memory Management 415Small block: External fragment<strong>at</strong>ionUnused space in alloc<strong>at</strong>ed block: Internal fragment<strong>at</strong>ionFigure 12.10 An illustr<strong>at</strong>ion of internal <strong>and</strong> external fragment<strong>at</strong>ion. The smallwhite block labeled ”External fragment<strong>at</strong>ion” is too small to s<strong>at</strong>isfy typical memoryrequests. The small grey block labeled ”Internal fragment<strong>at</strong>ion” was alloc<strong>at</strong>edas part of the grey block to its left, but it does not actually store inform<strong>at</strong>ion.block is found, then the memory manager must resort to a failure policy such asdiscussed in Section 12.3.2.If there is a request for m words, <strong>and</strong> no block exists of exactly size m, thena larger block must be used instead. One possibility in this case is th<strong>at</strong> the entireblock is given away to the memory alloc<strong>at</strong>ion request. This might be desirablewhen the size of the block is only slightly larger than the request. This is becausesaving a tiny block th<strong>at</strong> is too small to be useful for a future memory request mightnot be worthwhile. Altern<strong>at</strong>ively, for a free block of size k, with k > m, up tok − m space may be retained by the memory manager to form a new free block,while the rest is used to service the request.Memory managers can suffer from two types of fragment<strong>at</strong>ion, which refers tounused space th<strong>at</strong> is too small to be useful. External fragment<strong>at</strong>ion occurs whena series of memory requests <strong>and</strong> releases results in small free blocks. Internalfragment<strong>at</strong>ion occurs when more than m words are alloc<strong>at</strong>ed to a request for mwords, wasting free storage. This is equivalent to the internal fragment<strong>at</strong>ion th<strong>at</strong>occurs when files are alloc<strong>at</strong>ed in multiples of the cluster size. The differencebetween internal <strong>and</strong> external fragment<strong>at</strong>ion is illustr<strong>at</strong>ed by Figure 12.10.Some memory management schemes sacrifice space to internal fragment<strong>at</strong>ionto make memory management easier (<strong>and</strong> perhaps reduce external fragment<strong>at</strong>ion).For example, external fragment<strong>at</strong>ion does not happen in file management systemsth<strong>at</strong> alloc<strong>at</strong>e file space in clusters. Another example of sacrificing space to internalfragment<strong>at</strong>ion so as to simplify memory management is the buddy methoddescribed l<strong>at</strong>er in this section.The process of searching the memory pool for a block large enough to servicethe request, possibly reserving the remaining space as a free block, is referred to asa sequential fit method.Sequential Fit MethodsSequential-fit methods <strong>at</strong>tempt to find a “good” block to service a storage request.The three sequential-fit methods described here assume th<strong>at</strong> the free blocks areorganized into a doubly linked list, as illustr<strong>at</strong>ed by Figure 12.11.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!