1 Dynamic Memory Allocation. 2 Outline Implementation of a simple allocator Explicit Free List Segregated Free List Suggested reading: 10.9, 10.10, 10.11,

Slides:



Advertisements
Similar presentations
Dynamic Memory Management
Advertisements

Carnegie Mellon 1 Dynamic Memory Allocation: Basic Concepts : Introduction to Computer Systems 17 th Lecture, Oct. 21, 2010 Instructors: Randy Bryant.
Dynamic Memory Allocation I Topics Simple explicit allocators Data structures Mechanisms Policies CS 105 Tour of the Black Holes of Computing.
Dynamic Memory Allocation I Topics Basic representation and alignment (mainly for static memory allocation, main concepts carry over to dynamic memory.
Chris Riesbeck, Fall 2007 Dynamic Memory Allocation Today Dynamic memory allocation – mechanisms & policies Memory bugs.
1. Dynamic Memory Allocation. Dynamic Memory Allocation Programmers use dynamic memory allocators (such as malloc ) to acquire VM at run time.  For data.
Week 12 (March 28th) Outline Memory Allocation Lab 6 Reminders Lab 6: April 7 th (next Thurs) Start Early!!! Exam 2: April 5 th (Next Tue) TA: Kun Gao.
1 Binghamton University Dynamic Memory Allocation: Advanced Concepts CS220: Computer Systems II.
Dynamic Memory Allocation Topics Simple explicit allocators Data structures Mechanisms Policies.
Dynamic Memory Allocation I October 16, 2008 Topics Simple explicit allocators Data structures Mechanisms Policies lecture-15.ppt “The course that.
Dynamic Memory Allocation
1 Dynamic Memory Allocation: Basic Concepts Andrew Case Slides adapted from Jinyang Li, Randy Bryant and Dave O’Hallaro.
Recitation 10 Anubhav Gupta Section D.
Lab 3: Malloc Lab. “What do we need to do?”  Due 11/26  One more assignment after this one  Partnering  Non-Honors students may work with one other.
1 1 Lecture 4 Structure – Array, Records and Alignment Memory- How to allocate memory to speed up operation Structure – Array, Records and Alignment Memory-
Dynamic Memory Allocation I Nov 5, 2002 Topics Simple explicit allocators Data structures Mechanisms Policies class21.ppt “The course that gives.
– 1 – Dynamic Memory Allocation – beyond the stack and globals Stack Easy to allocate (decrement esp) Easy to deallocate (increment esp) Automatic allocation.
Dynamic Memory Allocation I May 21, 2008 Topics Simple explicit allocators Data structures Mechanisms Policies.
Dynamic Memory Allocation I November 1, 2006 Topics Simple explicit allocators Data structures Mechanisms Policies class18.ppt “The course that.
Recitation 9 (Nov. 8) Outline Virtual memory Lab 6 hints Reminders Lab 6: Get correctness points Exam 2: Nov. 16 (Next Tue) Minglong Shao
L6: Malloc Lab Writing a Dynamic Storage Allocator October 30, 2006
University of Washington Today Lab 5 out  Puts a *lot* together: pointers, debugging, C, etc.
Explicit Free Lists Use data space for link pointers –Typically doubly linked –Still need boundary tags for coalescing –It is important to realize that.
University of Washington Today Finished up virtual memory On to memory allocation Lab 3 grades up HW 4 up later today. Lab 5 out (this afternoon): time.
1 Dynamic Memory Allocation: Basic Concepts. 2 Today Basic concepts Implicit free lists.
Writing You Own malloc() March 29, 2003 Topics Explicit Allocation Data structures Mechanisms Policies class19.ppt “The course that gives CMU its.
CS 241 Discussion Section (11/17/2011). Outline Review of MP7 MP8 Overview Simple Code Examples (Bad before the Good) Theory behind MP8.
Consider Starting with 160 k of memory do: Starting with 160 k of memory do: Allocate p1 (50 k) Allocate p1 (50 k) Allocate p2 (30 k) Allocate p2 (30 k)
Dynamic Memory Allocation II
Carnegie Mellon 1 Bryant and O’Hallaron, Computer Systems: A Programmer’s Perspective, Third Edition Dynamic Memory Allocation: Basic Concepts :
Dynamic Memory Allocation April 9, 2002 Topics Simple explicit allocators Data structures Mechanisms Policies Reading: 10.9 Problems: and class21.ppt.
University of Washington Today More memory allocation!
CS 241 Discussion Section (2/9/2012). MP2 continued Implement malloc, free, calloc and realloc Reuse free memory – Sequential fit – Segregated fit.
Malloc Lab : Introduction to Computer Systems Recitation 11: Nov. 4, 2013 Marjorie Carlson Recitation A.
Carnegie Mellon 1 Dynamic Memory Allocation: Basic Concepts Instructors: Adapted from CMU course
CS 241 Discussion Section (12/1/2011). Tradeoffs When do you: – Expand Increase total memory usage – Split Make smaller chunks (avoid internal fragmentation)
CSE 351 Dynamic Memory Allocation 1. Dynamic Memory Dynamic memory is memory that is “requested” at run- time Solves two fundamental dilemmas: How can.
1 Dynamic Memory Allocation (II) Implementation. 2 Outline Implementation of a simple allocator Explicit Free List Segregated Free List Suggested reading:
University of Washington Implementation Issues How do we know how much memory to free given just a pointer? How do we keep track of the free blocks? How.
Dynamic Memory Allocation Alan L. Cox Some slides adapted from CMU slides.
Memory Management I: Dynamic Storage Allocation Oct 8, 1998 Topics User-level view Policies Mechanisms class14.ppt Introduction to Computer Systems.
Memory Management What if pgm mem > main mem ?. Memory Management What if pgm mem > main mem ? Overlays – program controlled.
Instructor: Phil Gibbons
Section 10: Memory Allocation Topics
CS 3214 Introduction to Computer Systems
Dynamic Memory Allocation I
Dynamic Memory Allocation
Instructor: Haryadi Gunawi
Memory Management I: Dynamic Storage Allocation Oct 7, 1999
Dynamic Memory Allocation I October 28, 2003
Dynamic Memory Allocation: Basic Concepts CS220: Computer Systems II
The Hardware/Software Interface CSE351 Winter 2013
Dynamic Memory Allocation – beyond the stack and globals
Memory Management I: Dynamic Storage Allocation March 2, 2000
User-Level Dynamic Memory Allocation: Malloc and Free
Dynamic Memory Allocation I
CS703 - Advanced Operating Systems
Dynamic Memory Allocation
Dynamic Memory Allocation I
Dynamic Memory Allocation: Basic Concepts /18-213/14-513/15-513: Introduction to Computer Systems 19th Lecture, October 30, 2018.
Memory Allocation II CSE 351 Autumn 2017
Memory Allocation II CSE 351 Winter 2018
Dynamic Memory Allocation November 2, 2000
Memory Allocation II CSE 351 Winter 2018
Dynamic Memory Allocation: Basic Concepts CSCI 380: Operating Systems
Dynamic Memory Allocation I
Instructors: Majd Sakr and Khaled Harras
CS703 - Advanced Operating Systems
Understanding mm-helper.c Adding debugging info to mm-helper.c
Presentation transcript:

1 Dynamic Memory Allocation

2 Outline Implementation of a simple allocator Explicit Free List Segregated Free List Suggested reading: 10.9, 10.10, 10.11, 10.12, 10.13

3 Dynamic Memory Allocation P731 Explicit vs. Implicit Memory Allocator –Explicit: application allocates and frees space E.g., malloc and free in C –Implicit: application allocates, but does not free space E.g. garbage collection in Java, ML or Lisp

4 Dynamic Memory Allocation Allocation –In both cases the memory allocator provides an abstraction of memory as a set of blocks –Doles out free memory blocks to application Doles: 发放

5 Malloc package P731 #include void *malloc(size_t size) –if successful: returns a pointer to a memory block of at least size bytes, aligned to 8-byte boundary. if size==0, returns NULL –if unsuccessful: returns NULL void free(void *p) –returns the block pointed at by p to pool of available memory –p must come from a previous call to malloc,calloc or realloc.

6 sbrk() Function P732 #include void *sbrk(int incr) –If successful It returns the old value of brk –If unsuccessful It returns –1 It sets errno to ENOMEM –If incr is zero It returns the current value –incr can be a negative number

Why Dynamic Memory Allocation

8 1 #include "csapp.h" 2 #define MAXN int array[MAXN]; 5 6 int main() 7 { 8 int i, n; 9 10 scanf("%d", &n); 11 if (n > MAXN) 12 app_error("Input file too big"); 13 for (i = 0; i < n; i++) 14 scanf("%d", &array[i]); 15 exit(0); 16 } Why Dynamic Memory Allocation P734

9 1 #include "csapp.h" 2 3 int main() 4 { 5 int *array, i, n; 6 7 scanf("%d", &n); 8 array = (int *)Malloc(n * sizeof(int)); 9 for (i = 0; i < n; i++) 10 scanf("%d", &array[i]); 11 exit(0); 12 } Why Dynamic Memory Allocation P734

10 Assumptions made in this lecture –memory is word addressed (each word can hold a pointer) Allocated block (4 words) Free block (3 words) Free word Allocated word Assumptions

11 p1 = malloc(4) p2 = malloc(5) p3 = malloc(6) free(p2) p4 = malloc(2) Allocation examples Figure P733

Allocator Requirements and Goals

13 Constraints Applications: –Can issue arbitrary sequence of allocation and free requests –Free requests must correspond to an allocated block

14 Constraints Allocators –Can’t control number or size of allocated blocks –Must respond immediately to all allocation requests i.e., can’t reorder or buffer requests –Must allocate blocks from free memory i.e., can only place allocated blocks in free memory

15 Constraints Allocators –Must align blocks so they satisfy all alignment requirements usually 8 byte alignment –Can only manipulate and modify free memory –Can’t move the allocated blocks once they are allocated i.e., compaction is not allowed

16 Goals P735 Given some sequence of malloc and free requests: – R 0, R 1,..., R k,..., R n-1 Want to maximize throughput and peak memory utilization. –These goals are often conflicting

17 Performance goals: throughput Number of completed requests per unit time Example: –5,00 malloc calls and 5,00 free calls in 1 seconds –throughput is 1,000 operations/second.

18 Performance goals: peak memory utilization Given some sequence of malloc and free requests: – R 0, R 1,..., R k,..., R n-1 Def: aggregate payload P k : – malloc(p) results in a block with a payload of p bytes. –After request R k has completed, the aggregate payload P k is the sum of currently allocated payloads. Aggregate: 合计,累计

19 Performance goals: peak memory utilization Given some sequence of malloc and free requests: – R 0, R 1,..., R k,..., R n-1 Def: current heap size is denoted by H k –Note that H k is monotonically nondecreasing Def: peak memory utilization: –After k requests, peak memory utilization is: U k = ( max i<k P i ) / H k

Fragmentation Fragmentation: 分裂

21 Fragmentation Poor memory utilization caused by fragmentation –Comes in two forms: internal fragmentation external fragmentation

22 Internal Fragmentation Internal fragmentation –For some block, internal fragmentation is the difference between the block size and the payload size payload Internal fragmentation block Internal fragmentation

23 Internal Fragmentation Internal fragmentation –Is caused by overhead of maintaining heap data structures, padding for alignment purposes, or explicit policy decisions (e.g., not to split the block). –Depends only on the pattern of previous requests, and thus is easy to measure.

24 External fragmentation Occurs when there is enough aggregate heap memory, but no single free block is large enough p1 = malloc(4) p2 = malloc(5) p3 = malloc(6) free(p2) p4 = malloc(6)

25 External fragmentation External fragmentation depends on –the pattern of future requests –and thus is difficult to measure

Implementation Issues

27 Implementation issues How do we know how much memory to free just given a pointer? How do we keep track of the free blocks? p1 = malloc(1) p0 free(p0)

28 Implementation issues What do we do with the extra space when allocating a structure that is smaller than the free block it is placed in? How do we pick a block to use for allocation –many might fit? How do we reinsert freed block? Reinsert :重新插入

29 Knowing how much to free Standard method –keep the length of a structure in the word preceding the structure This word is often called the header field or header –requires an extra word for every allocated structure

30 Knowing how much to free free(p0) p0 = malloc(4)p0 Block sizedata 5

Implicit Free Lists

32 Implicit list Need to identify whether each block is free or allocated –Can use extra bit –Bit can be put in the same word as the size if block sizes are always multiples of 8 (mask out low order bit when reading size).

33 Implicit list size 1 word Format of allocated and free blocks payload a = 1: allocated block a = 0: free block size: block size payload: application data (allocated blocks only) a optional padding p Figure P738

Placing Allocated Blocks

35 Finding a free block 1 ) First fit: –Search list from beginning, choose first free block that fits –Can take linear time in total number of blocks (allocated and free) –In practice it can cause “splinters” at beginning of list p = start; while ((p < end) ||\\ not passed end (*p & 1) || \\ already allocated (*p <= len) );\\ too small

36 Finding a free block 2 ) Next fit : –Like first-fit, but search list from location of end of previous search –Research suggests that fragmentation is worse 3 ) Best fit: –Search the list, choose the free block with the closest size that fits –Keeps fragments small --- usually helps fragmentation –Will typically run slower than first-fit

Splitting Free Blocks

38 Allocating in a free block Allocating in a free block - splitting –Since allocated space might be smaller than free space, we might want to split the block 4426 p

Getting Additional Heap Memory

Coalescing Free Blocks Coalescing :接合

41 Freeing a block Simplest implementation: –Only need to clear allocated flag –But can lead to “false fragmentation” –There is enough free space, but the allocator won’t be able to find it free(p) p malloc(5)

42 Coalescing Join with next and/or previous block if they are free –Coalescing with next block –But how do we coalesce with previous block? free(p) p

Coalescing with Boundary Tags

44 Bidirectional Boundary tags [Knuth73] –replicate size/allocated word at bottom of free blocks –Allows us to traverse the “list” backwards, but requires extra space –Important and general technique!

45 Bidirectional size 1 word Format of allocated and free blocks payload and padding a = 1: allocated block a = 0: free block size: block size payload: application data (allocated blocks only) a sizea boundary tag (footer) header Figure P742

46 allocated free allocated free block being freed Case 1Case 2Case 3Case 4 Constant time coalescing Figure P743

47 m11 1 n1 n1 m21 1 m11 1 n0 n0 m21 1 Constant time coalescing (case 1)

48 m11 1 n+m20 0 m11 1 n1 n1 m20 0 Constant time coalescing (case 2)

49 m10 0 n1 n1 m21 1 n+m10 0 m21 1 Constant time coalescing (case 3)

50 m10 0 n1 n1 m20 0 n+m1+m20 0 Constant time coalescing (case 4)

Putting it Together: Implementing a Simple Allocator

52 1 int mm_init(void); 2 void *mm_malloc(size_t size); 3 void mm_free(void *bp); Implementing a Simple Allocator

53 Data Structure Figure P745

54 1 #include "csapp.h" 2 3 /* private global variables */ 4 static void *mem_start_brk; /* points to first byte of the heap */ 5 static void *mem_brk; /* points to last byte of the heap */ 6 static void *mem_max_addr; /* max virtual address for the heap */ 7 8 /* 9 * mem_init - initializes the memory system model 10 */ 11 void mem_init(int size) 12 { 13 mem_start_brk = (void *)Malloc(size); /* models available VM */ 14 mem_brk = mem_start_brk; /* heap is initially empty */ 15 mem_max_addr = mem_start_brk + size; /* max VM address for heap */ 16 } 17 Initialize Figure P745

55 18 /* 19 * mem_sbrk - simple model of the the sbrk function. Extends the heap 20 * by incr bytes and returns the start address of the new area. In 21 * this model, the heap cannot be shrunk. 22 */ 23 void *mem_sbrk(int incr) 24 { 25 void *old_brk = mem_brk; if ( (incr mem_max_addr)) { 28 errno = ENOMEM; 29 return (void *)-1; 30 } 31 mem_brk += incr; 32 return old_brk; 33 } Initialize

56 1 /* Basic constants and macros */ 2 #define WSIZE 4 /* word size (bytes) */ 3 #define DSIZE 8 /* doubleword size (bytes) */ 4 #define CHUNKSIZE (1<<12) /* initial heap size (bytes) */ 5 #define OVERHEAD 8 /* overhead of header and footer (bytes) */ 6 7 #define MAX(x, y) ((x) > (y)? (x) : (y)) 8 9 /* Pack a size and allocated bit into a word */ 10 #define PACK(size, alloc) ((size) | (alloc)) /* Read and write a word at address p */ 13 #define GET(p) (*(size_t *)(p)) 14 #define PUT(p, val) (*(size_t *)(p) = (val)) 15 Macros Figure P746

57 16 /* Read the size and allocated fields from address p */ 17 #define GET_SIZE(p) (GET(p) & ˜0x7) 18 #define GET_ALLOC(p) (GET(p) & 0x1) /* Given block ptr bp, compute address of its header and footer */ 21 #define HDRP(bp) ((void *)(bp) - WSIZE) 22 #define FTRP(bp) ((void *)(bp) + GET_SIZE(HDRP(bp)) - DSIZE) /* Given block ptr bp, compute address of next and previous blocks */ 25 #define NEXT_BLKP(bp) ((void *)(bp) + GET_SIZE(HDRP(bp))) 26#define PREV_BLKP(bp) ((void *)(bp) - GET_SIZE(((void *)(bp) - DSIZE))) size t size = GET SIZE(HDRP(NEXT_BLKP(bp))); Macros

58 1 int mm_init(void) 2 { 3 /* create the initial empty heap */ 4 if ((heap_listp = mem_sbrk(4*WSIZE)) == NULL) 5 return -1; 6 PUT(heap_listp, 0); /* alignment padding */ 7 PUT(heap_listp+WSIZE, PACK(OVERHEAD, 1)); /* prologue header */ 8 PUT(heap_listp+DSIZE, PACK(OVERHEAD, 1)); /* prologue footer */ 9 PUT(heap_listp+WSIZE+DSIZE, PACK(0, 1)); /* epilogue header */ 10 heap_listp += DSIZE; /* Extend the empty heap with a free block of CHUNKSIZE bytes */ 13 if (extend_heap(CHUNKSIZE/WSIZE) == NULL) 14 return -1; 15 return 0; 16 } mm_init() Figure P747

59 1 static void *extend_heap(size_t words) 2 { 3 char *bp; 4 size_t size; 5 6 /* Allocate an even number of words to maintain alignment */ 7 size = (words % 2) ? (words+1) * WSIZE : words * WSIZE; 8 if ((int)(bp = mem_sbrk(size)) < 0) 9 return NULL; /* Initialize free block header/footer and the epilogue header */ 12 PUT(HDRP(bp), PACK(size, 0)); /* free block header */ 13 PUT(FTRP(bp), PACK(size, 0)); /* free block footer */ 14 PUT(HDRP(NEXT_BLKP(bp)), PACK(0, 1)); /* new epilogue header */ /* Coalesce if the previous block was free */ 17 return coalesce(bp); 18 } mm_init() Figure P748

60 1 void mm_free(void *bp) 2 { 3 size_t size = GET_SIZE(HDRP(bp)); 4 5 PUT(HDRP(bp), PACK(size, 0)); 6 PUT(FTRP(bp), PACK(size, 0)); 7 coalesce(bp); 8 } 9 mm_free() Figure P749

61 10 static void *coalesce(void *bp) 11 { 12 size_t prev_alloc = GET_ALLOC(FTRP(PREV_BLKP(bp))); 13 size_t next_alloc = GET_ALLOC(HDRP(NEXT_BLKP(bp))); 14 size_t size = GET_SIZE(HDRP(bp)); if (prev_alloc && next_alloc) { /* Case 1 */ 17 return bp; 18 } else if (prev_alloc && !next_alloc) { /* Case 2 */ 21 size += GET_SIZE(HDRP(NEXT_BLKP(bp))); 22 PUT(HDRP(bp), PACK(size, 0)); 23 PUT(FTRP(bp), PACK(size,0)); 24 return(bp); 25 } 26 mm_free()

62 27 else if (!prev_alloc && next_alloc) { /* Case 3 */ 28 size += GET_SIZE(HDRP(PREV_BLKP(bp))); 29 PUT(FTRP(bp), PACK(size, 0)); 30 PUT(HDRP(PREV_BLKP(bp)), PACK(size, 0)); 31 return(PREV_BLKP(bp)); 32 } else { /* Case 4 */ 35 size += GET_SIZE(HDRP(PREV_BLKP(bp))) + 36 GET_SIZE(FTRP(NEXT_BLKP(bp))); 37 PUT(HDRP(PREV_BLKP(bp)), PACK(size, 0)); 38 PUT(FTRP(NEXT_BLKP(bp)), PACK(size, 0)); 39 return(PREV_BLKP(bp)); 40 } 41 } mm_free() Figure P749

63 1 void *mm_malloc (size_t size) 2 { 3 size_t asize; /* adjusted block size */ 4 size_t extendsize; /* amount to extend heap if no fit */ 5 char *bp; 6 7 /* Ignore spurious requests */ 8 if (size <= 0) 9 return NULL; /* Adjust block size to include overhead and alignment reqs. */ 12 if (size <= DSIZE) 13 asize = DSIZE + OVERHEAD; 14 else 15 asize = DSIZE * ((size + (OVERHEAD) + (DSIZE-1)) / DSIZE); 16 mm_malloc() Figure P750

64 17 /* Search the free list for a fit */ 18 if ((bp = find_fit(asize)) != NULL) { 19 place (bp, asize); 20 return bp; 21 } /* No fit found. Get more memory and place the block */ 24 extendsize = MAX (asize, CHUNKSIZE) ; 25 if ((bp = extend_heap (extendsize/WSIZE)) == NULL) 26 return NULL; 27 place (bp, asize); 28 return bp; 29 } mm_malloc()

65 1.static void *find_fit(size_t asize) 2.{ 3. void *bp ; /* first fit search */ 6. for (bp = heap_listp; GET_SIZE(HDRP(bp)) > 0 ; bp = NEXT_BLKP(bp) ) { 7. if (!GET_ALLOC(HDRP(bp)) && (asize<=GET_SIZE(HDRP(bp)))) { 8. return bp; 9. } 10. } 11. return NULL; /*no fit */ 12. } mm_alloc()

66 1. static void place(void *bp, size_t asize) 2. { 3. size_t csize = GET_SIZE(HDRP(bp)) ; if ( (csize –asize) >= (DSIZE + OVERHEAD) ) { 6. PUT(HDRP(bp), PACK(asize, 1)) ; 7. PUT(FTRP(bp), PACK(asize, 1)) ; 8. bp = NEXT_BLKP(bp) ; 9. PUT(HDRP(bp), PACK(csize-asize, 0) ; 10. PUT(FTRP(bp), PACK(csize-asize, 0) ; 11. } else { 12. PUT(HDRP(bp), PACK(csize, 1) ; 13. PUT(FTRP(bp), PACK(csize, 1) ; 14. } 15.} mm_alloc()

Explicit Free Lists

68 Explicit free lists Explicit list among the free blocks using pointers within the free blocks 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

69 Explicit free lists ABC Forward links Back links A B C

70 Freeing with explicit free lists Where to put the newly freed block in the free list –LIFO (last-in-first-out) policy insert freed block at the beginning of the free list pro: simple and constant time con: studies suggest fragmentation is worse than address ordered.

71 Freeing with explicit free lists Where to put the newly freed block in the free list –Address-ordered policy insert freed blocks so that free list blocks are always in address order –i.e. addr(pred) < addr(curr) < addr(succ) con: requires search pro: studies suggest fragmentation is better than LIFO

Segregated Free Lists

73 Segregated Storage Each size “class” has its own collection of blocks –Often have separate collection for every small size (2,3,4,…) –For larger sizes typically have a collection for each power of 2

74 Segregated Storage

75 Separate heap and free list for each size class No splitting To allocate a block of size n: –if free list for size n is not empty, allocate first block on list (note, list can be implicit or explicit) –if free list is empty, get a new page create new free list from all blocks in page allocate first block on list –constant time 1) Simple segregated storage

76 To free a block: –Add to free list –If page is empty, return the page for use by another size (optional) Tradeoffs: –fast, but can fragment badly Simple segregated storage

77 Array of free lists, each one for some size class 2) Segregated fits

78 To allocate a block of size n: –search appropriate free list for block of size m > n –if an appropriate block is found: split block and place fragment on appropriate list (optional) –if no block is found, try next larger class –repeat until block is found –if no blocks is found in all classes, try more heap memory Segregated fits

79 To free a block: –coalesce and place on appropriate list (optional) Tradeoffs –faster search than sequential fits (i.e., log time for power of two size classes) –controls fragmentation of simple segregated storage –coalescing can increase search times deferred coalescing can help Segregated fits

80 A special case of segregated fits –Each size is power of 2 Initialize –A heap of size 2 m 3) Buddy Systems

81 Allocate –Roundup to power of 2 such as 2 k –Find a free block of size 2 j (k  j  m) –Split the block in half until j=k Each remaining half block (buddy) is placed on the appreciate free list Free –Continue coalescing with the free buddies Buddy Systems

Garbage Collection

Common Memory-Related Bugs in C Programs

Recapping Some Key Ideas About Virtual Memory

Summary