lecture26 - CIS 450 Computer Architecture and Organization...

Info iconThis preview shows pages 1–13. Sign up to view the full content.

View Full Document Right Arrow Icon
CIS 450 – Computer Architecture and Organization Lecture 26: Dynamic Memory Allocation (cont.) Mitch Neilsen ([email protected] ) 219D Nichols Hall
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Topics ± Explicit doubly-linked free lists ± Segregated free lists ± Garbage collection ± Review of pointers ± Memory-related perils and pitfalls
Background image of page 2
Keeping Track of Free Blocks z Method 1 : Implicit list using lengths -- links all blocks z Method 2 : Explicit list among the free blocks using pointers within the free blocks z Method 3 : Segregated free lists ± Different free lists for different size classes z Method 4 : Blocks sorted by size (not discussed) ± Can use a balanced tree (e.g. Red-Black tree) with pointers within each free block, and the length used as a key 5 4 2 6 5 4 2 6
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Explicit Free Lists Use data space for link pointers ± Typically doubly linked ± Still need boundary tags for coalescing ± It is important to realize that links are not necessarily in the same order as the blocks A B C 4 4 4 4 6 6 4 4 4 4 Forward links Back links A B C
Background image of page 4
Allocating From Explicit Free Lists Before: After: = malloc(…) (with splitting)
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Freeing With Explicit Free Lists Insertion policy : Where in the free list do you put a newly freed block? ± LIFO (last-in-first-out) policy z Insert freed block at the beginning of the free list z Pro: simple and constant time z Con: studies suggest fragmentation is worse than address ordered. ± Address-ordered policy z Insert freed blocks so that free list blocks are always in address order » i.e. addr(pred) < addr(curr) < addr(succ) z Con: requires search z Pro: studies suggest fragmentation is lower than LIFO
Background image of page 6
Freeing With a LIFO Policy (Case 1) Insert the freed block at the root of the list free( ) Root Root Before: After:
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Freeing With a LIFO Policy (Case 2) Splice out predecessor block, coalesce both memory blocks and insert the new block at the root of the list free( ) Root Root Before: After:
Background image of page 8
Freeing With a LIFO Policy (Case 3) Splice out successor block, coalesce both memory blocks and insert the new block at the root of the list free( ) Root Root Before: After:
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Freeing With a LIFO Policy (Case 4) Splice out predecessor and successor blocks, coalesce all 3 memory blocks and insert the new block at the root of the list free( ) Root Root Before: After:
Background image of page 10
Explicit List Summary Comparison to implicit list: ± Allocate is linear time in number of free blocks instead of total blocks -- z much faster allocates when most of the memory is full ± Slightly more complicated allocate and free since needs to splice blocks in and out of the list ± Some extra space for the links (2 extra words needed for each block) Main use of linked lists is in conjunction with segregated free lists ± Keep multiple linked lists of different size classes, or possibly for different types of objects
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Keeping Track of Free Blocks Method 1 : Implicit list using lengths -- links all blocks Method 2 : Explicit list among the free blocks using pointers within the free blocks Method 3 : Segregated free list
Background image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/09/2008 for the course CIS 450 taught by Professor Neilsen,mitch during the Spring '08 term at Kansas State University.

Page1 / 40

lecture26 - CIS 450 Computer Architecture and Organization...

This preview shows document pages 1 - 13. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online