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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

420 Chap. 12 Lists <strong>and</strong> Arrays RevisitedBuddies0000Buddies000001001000Buddies10001100(a)Figure 12.14 Example of the buddy system. (a) Blocks of size 8. (b) Blocks ofsize 4.The reason why this method is called the buddy system is because of the wayth<strong>at</strong> merging takes place. The buddy for any block of size 2 k is another blockof the same size, <strong>and</strong> with the same address (i.e., the byte position in memory,read as a binary value) except th<strong>at</strong> the kth bit is reversed. For example, the blockof size 8 with beginning address 0000 in Figure 12.14(a) has buddy with address1000. Likewise, in Figure 12.14(b), the block of size 4 with address 0000 hasbuddy 0100. If free blocks are sorted by address value, the buddy can be found bysearching the correct block-size list. Merging simply requires th<strong>at</strong> the address forthe combined buddies be moved to the freelist for the next larger block size.(b)Other Memory Alloc<strong>at</strong>ion MethodsIn addition to sequential-fit <strong>and</strong> buddy methods, there are many ad hoc approachesto memory management. If the applic<strong>at</strong>ion is sufficiently complex, it might bedesirable to break available memory into several memory zones, each with a differentmemory management scheme. For example, some zones might have a simplememory access p<strong>at</strong>tern of first-in, first-out. This zone can therefore be managed efficientlyby using a simple stack. Another zone might alloc<strong>at</strong>e only records of fixedsize, <strong>and</strong> so can be managed with a simple freelist as described in Section 4.1.2.Other zones might need one of the general-purpose memory alloc<strong>at</strong>ion methodsdiscussed in this section. The advantage of zones is th<strong>at</strong> some portions of memorycan be managed more efficiently. The disadvantage is th<strong>at</strong> one zone might fill upwhile other zones have excess free memory if the zone sizes are chosen poorly.Another approach to memory management is to impose a st<strong>and</strong>ard size on allmemory requests. We have seen an example of this concept already in disk filemanagement, where all files are alloc<strong>at</strong>ed in multiples of the cluster size. Thisapproach leads to internal fragment<strong>at</strong>ion, but managing files composed of clusters

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

Saved successfully!

Ooh no, something went wrong!