DOC PREVIEW
CMU CS 15213 - Recitation

This preview shows page 1-2-21-22 out of 22 pages.

Save
View full document
Premium Document
Do you want full access? Go Premium and unlock all 22 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

15213 Recitation Section C Shimin Chen Nov 11 2002 Outline Understanding mm helper c Adding debugging info to mm helper c What does mm helper c do Implicit Free List Header with each block size allocated bit No separate Free List free blocks linked implicitly by size fields in header First Fit Searches free list from beginning and picks first block that is large enough Immediate Boundary Tag Coalescing Footer boundary tag replica of header 15213 Recitation C 2 Shimin Chen Block Format Header 32 bits Pointer returned by malloc Block Pointer bp Payload Footer 15213 Recitation C 3 what user asked for in malloc 32 bits Shimin Chen Header Footer Format 3 31 size 1 0 0 0 a Double word alignment 2 Three lower order bits of size always 0 Pack size and allocated bits into a single integer 15213 Recitation C Size 24 0x18 Block is allocated Header 0 x18 0x1 0x19 4 Shimin Chen Heap Format 4 bytes Pad Prologue 8 1 8 1 Epilogue Footer Header Header Footer 0 1 Allocated and Free Blocks Double Word Alignment 8 bytes 15213 Recitation C 5 Shimin Chen Very Useful Macros define WSIZE 4 define DSIZE 8 define CHUNKSIZE 1 12 define OVERHEAD 8 15213 Recitation C 6 Shimin Chen Very Useful Macros define PACK size alloc size alloc define GET p size t p define PUT p val size t p val define GET SIZE p GET p 0x7 define GET ALLOC p GET p 0x1 15213 Recitation C 7 Shimin Chen Very Useful Macros define HDRP bp char bp WSIZE define FTRP bp char bp GET SIZE HDRP bp DSIZE define NEXT BLKP bp char bp GET SIZE char bp WSIZE define PREV BLKP bp char bp GET SIZE char bp DSIZE 15213 Recitation C 8 Shimin Chen Initializing the Heap int mm init void if heap listp mem sbrk 4 WSIZE NULL return 1 PUT heap listp 0 PUT heap listp WSIZE PACK OVERHEAD 1 PUT heap listp DSIZE PACK OVERHEAD 1 PUT heap listp WSIZE DSIZE PACK 0 1 heap listp DSIZE if extend heap CHUNKSIZE WSIZE NULL return 1 return 0 15213 Recitation C 9 Shimin Chen Extending the Heap static void extend heap size t words char bp size t size size words 2 words 1 WSIZE words WSIZE if int bp mem sbrk size 0 return NULL PUT HDRP bp PACK size 0 PUT FTRP bp PACK size 0 PUT HDRP NEXT BLKP bp PACK 0 1 return coalesce bp 15213 Recitation C 10 Shimin Chen Malloc void mm malloc size t size size t asize extendsize char bp if size if size asize else asize 0 return NULL DSIZE DSIZE OVERHEAD DSIZE size OVERHEAD DSIZE 1 DSIZE if bp find fit asize NULL place bp asize return bp extendsize MAX asize CHUNKSIZE if bp extend heap extendsize WSIZE NULL return NULL place bp asize return bp 15213 Recitation C 11 Shimin Chen Finding First Fit static void find fit size t asize void bp for bp heap listp GET SIZE HDRP bp 0 bp NEXT BLKP bp if GET ALLOC HDRP bp asize GET SIZE HDRP bp return bp return NULL 15213 Recitation C 12 Shimin Chen Malloc void mm malloc size t size size t asize extendsize char bp if size if size asize else asize 0 return NULL DSIZE DSIZE OVERHEAD DSIZE size OVERHEAD DSIZE 1 DSIZE if bp find fit asize NULL place bp asize return bp extendsize MAX asize CHUNKSIZE if bp extend heap extendsize WSIZE NULL return NULL place bp asize return bp 15213 Recitation C 13 Shimin Chen Placing a Block in a Free Block static void place void bp size t asize size t csize GET SIZE HDRP bp if csize asize DSIZE OVERHEAD PUT HDRP bp PACK asize 1 PUT FTRP bp PACK asize 1 bp NEXT BLKP bp PUT HDRP bp PACK csize asize 0 PUT FTRP bp PACK csize asize 0 else PUT HDRP bp PACK csize 1 PUT FTRP bp PACK csize 1 15213 Recitation C 14 Shimin Chen Malloc void mm malloc size t size size t asize extendsize char bp if size if size asize else asize 0 return NULL DSIZE DSIZE OVERHEAD DSIZE size OVERHEAD DSIZE 1 DSIZE if bp find fit asize NULL place bp asize return bp extendsize MAX asize CHUNKSIZE if bp extend heap extendsize WSIZE NULL return NULL place bp asize return bp 15213 Recitation C 15 Shimin Chen Free void mm free void bp size t size GET SIZE HDRP bp PUT HDRP bp PACK size 0 PUT FTRP bp PACK size 0 coalesce bp 15213 Recitation C 16 Shimin Chen Coalesce Called by mm free extend heap static void coalesce void bp size t prev alloc GET ALLOC FTRP PREV BLKP bp size t next alloc GET ALLOC HDRP NEXT BLKP bp size t size GET SIZE HDRP bp if prev alloc next alloc return bp else if prev alloc next alloc else if prev alloc next alloc size GET SIZE HDRP PREV BLKP bp PUT FTRP bp PACK size 0 PUT HDRP PREV BLKP bp PACK size 0 bp PREV BLKP bp else return bp 15213 Recitation C 17 Shimin Chen Adding Debugging Information mm heapcheck Display request id and payload of every active block request id malloc request counter 0 mm init sets the counter to 0 mm malloc increments the counter payload size the memory requested by malloc Can be different from the allocated size We need to store the info somewhere 15213 Recitation C 18 Shimin Chen Allocated Block Format Header 32 bits request id 32 bits payload size Pointer returned to user Payload Footer 15213 Recitation C 19 32 bits what user asked for in malloc 32 bits Shimin Chen One Way to Implement This Inside malloc Allocate additional memory in malloc PUT bp request counter PUT bp 4 size return bp DSIZE Inside Free 15213 Recitation C bp bp DSIZE 20 Shimin Chen Heapcheck Put all sorts of sanity checks Scan the implicit list like the first fit function print request id and size 15213 Recitation C 21 Shimin Chen Explicit Lists Separate Free List Change Free Block Format Add prev pointer Add next pointer Where to store free list pointer Can find a free block quickly Only one WORD Can store in unused PAD word Some functions to add static void insertfree block void freeblkptr static void removefree block void freeblkptr 15213 Recitation C 22 Shimin Chen


View Full Document

CMU CS 15213 - Recitation

Documents in this Course
lecture

lecture

14 pages

lecture

lecture

46 pages

Caches

Caches

9 pages

lecture

lecture

39 pages

Lecture

Lecture

36 pages

Lecture

Lecture

45 pages

Lecture

Lecture

56 pages

lecture

lecture

11 pages

lecture

lecture

9 pages

Lecture

Lecture

36 pages

Lecture

Lecture

37 pages

Exam

Exam

16 pages

Lecture

Lecture

10 pages

Lecture

Lecture

43 pages

Lecture

Lecture

8 pages

Lecture

Lecture

8 pages

Lecture

Lecture

36 pages

Lecture

Lecture

43 pages

Lecture

Lecture

12 pages

Lecture

Lecture

37 pages

Lecture

Lecture

6 pages

Lecture

Lecture

40 pages

coding

coding

2 pages

Exam

Exam

17 pages

Exam

Exam

14 pages

Lecture

Lecture

29 pages

Lecture

Lecture

34 pages

Exam

Exam

11 pages

Lecture

Lecture

9 pages

Lecture

Lecture

37 pages

Lecture

Lecture

36 pages

lecture

lecture

46 pages

Lecture

Lecture

33 pages

Lecture

Lecture

57 pages

Lecture

Lecture

32 pages

Lecture

Lecture

46 pages

Lecture

Lecture

40 pages

Lecture

Lecture

11 pages

Lecture

Lecture

6 pages

Lecture

Lecture

43 pages

Lecture

Lecture

12 pages

Lecture

Lecture

18 pages

Exam

Exam

10 pages

Lecture

Lecture

45 pages

Lecture

Lecture

37 pages

Exam

Exam

24 pages

class09

class09

21 pages

class22

class22

37 pages

class20

class20

30 pages

class27

class27

33 pages

class25

class25

21 pages

class04

class04

31 pages

Lecture

Lecture

59 pages

class01a

class01a

14 pages

class12

class12

45 pages

class29

class29

33 pages

Lecture

Lecture

39 pages

Lecture

Lecture

6 pages

class03

class03

34 pages

lecture

lecture

42 pages

Lecture

Lecture

40 pages

Lecture

Lecture

47 pages

Exam

Exam

19 pages

R06-B

R06-B

25 pages

class17

class17

37 pages

class25

class25

31 pages

Lecture

Lecture

15 pages

final-f06

final-f06

17 pages

Lecture

Lecture

9 pages

lecture

lecture

9 pages

Exam

Exam

15 pages

Lecture

Lecture

22 pages

class11

class11

45 pages

lecture

lecture

50 pages

Linking

Linking

37 pages

Lecture

Lecture

64 pages

Integers

Integers

40 pages

Exam

Exam

11 pages

Lecture

Lecture

37 pages

Lecture

Lecture

44 pages

Lecture

Lecture

37 pages

Lecture

Lecture

9 pages

Lecture

Lecture

37 pages

Lecture

Lecture

45 pages

Final

Final

25 pages

lecture

lecture

9 pages

Lecture

Lecture

30 pages

Lecture

Lecture

16 pages

Final

Final

17 pages

Lecture

Lecture

8 pages

Exam

Exam

11 pages

Lecture

Lecture

47 pages

Lecture

Lecture

9 pages

lecture

lecture

39 pages

Exam

Exam

11 pages

lecture

lecture

41 pages

lecture

lecture

37 pages

Lecture

Lecture

59 pages

Lecture

Lecture

45 pages

Exam 1

Exam 1

18 pages

Lecture

Lecture

41 pages

Lecture

Lecture

32 pages

Lecture

Lecture

30 pages

Lecture

Lecture

9 pages

Lecture

Lecture

9 pages

Lecture

Lecture

15 pages

Lecture

Lecture

11 pages

Lecture

Lecture

9 pages

Lecture

Lecture

34 pages

Lecture

Lecture

40 pages

Lecture

Lecture

4 pages

Lecture

Lecture

46 pages

Lecture

Lecture

8 pages

Lecture

Lecture

65 pages

Lecture

Lecture

38 pages

Lecture

Lecture

35 pages

Lecture

Lecture

8 pages

Lecture

Lecture

34 pages

Lecture

Lecture

8 pages

Exam

Exam

13 pages

Lecture

Lecture

43 pages

Lecture

Lecture

9 pages

Lecture

Lecture

12 pages

Lecture

Lecture

9 pages

Lecture

Lecture

34 pages

Lecture

Lecture

43 pages

Lecture

Lecture

7 pages

Lecture

Lecture

45 pages

Lecture

Lecture

24 pages

Lecture

Lecture

47 pages

Lecture

Lecture

12 pages

Lecture

Lecture

20 pages

Lecture

Lecture

9 pages

Exam

Exam

11 pages

Lecture

Lecture

52 pages

Lecture

Lecture

20 pages

Exam

Exam

11 pages

Lecture

Lecture

35 pages

Lecture

Lecture

47 pages

Lecture

Lecture

18 pages

Lecture

Lecture

30 pages

Lecture

Lecture

59 pages

Lecture

Lecture

37 pages

Lecture

Lecture

22 pages

Lecture

Lecture

35 pages

Exam

Exam

23 pages

Lecture

Lecture

9 pages

Lecture

Lecture

22 pages

class12

class12

32 pages

Lecture

Lecture

8 pages

Lecture

Lecture

39 pages

Lecture

Lecture

44 pages

Lecture

Lecture

38 pages

Lecture

Lecture

69 pages

Lecture

Lecture

41 pages

Lecture

Lecture

12 pages

Lecture

Lecture

52 pages

Lecture

Lecture

59 pages

Lecture

Lecture

39 pages

Lecture

Lecture

83 pages

Lecture

Lecture

59 pages

class01b

class01b

17 pages

Exam

Exam

21 pages

class07

class07

47 pages

Lecture

Lecture

11 pages

Odyssey

Odyssey

18 pages

multicore

multicore

66 pages

Lecture

Lecture

6 pages

lecture

lecture

41 pages

lecture

lecture

55 pages

lecture

lecture

52 pages

lecture

lecture

33 pages

lecture

lecture

46 pages

lecture

lecture

55 pages

lecture

lecture

17 pages

lecture

lecture

49 pages

Exam

Exam

17 pages

lecture

lecture

56 pages

Exam 2

Exam 2

16 pages

Exam 2

Exam 2

16 pages

Notes

Notes

37 pages

Lecture

Lecture

40 pages

Lecture

Lecture

36 pages

Lecture

Lecture

43 pages

Lecture

Lecture

25 pages

Exam

Exam

13 pages

Lecture

Lecture

32 pages

Lecture

Lecture

12 pages

Lecture

Lecture

58 pages

Lecture

Lecture

29 pages

Lecture

Lecture

59 pages

Lecture

Lecture

41 pages

Lecture

Lecture

50 pages

Exam

Exam

17 pages

Lecture

Lecture

29 pages

Lecture

Lecture

44 pages

Lecture

Lecture

41 pages

Lecture

Lecture

52 pages

Lecture

Lecture

40 pages

Lecture

Lecture

33 pages

lecture

lecture

10 pages

Lecture

Lecture

27 pages

Lecture

Lecture

29 pages

Lecture

Lecture

39 pages

Lecture

Lecture

9 pages

Lecture

Lecture

29 pages

Lecture

Lecture

8 pages

Lecture

Lecture

43 pages

Lecture

Lecture

43 pages

Lecture

Lecture

75 pages

Lecture

Lecture

55 pages

Exam

Exam

12 pages

Lecture

Lecture

43 pages

Lecture

Lecture

35 pages

lecture

lecture

36 pages

Exam

Exam

33 pages

lecture

lecture

56 pages

lecture

lecture

64 pages

lecture

lecture

8 pages

Exam

Exam

14 pages

Lecture

Lecture

43 pages

Lecture

Lecture

36 pages

lecture

lecture

56 pages

lecture

lecture

75 pages

lecture

lecture

36 pages

Lecture

Lecture

50 pages

Lecture

Lecture

45 pages

Lecture

Lecture

13 pages

Exam

Exam

23 pages

Lecture

Lecture

10 pages

Lecture

Lecture

48 pages

Lecture

Lecture

83 pages

lecture

lecture

57 pages

Lecture

Lecture

33 pages

Lecture

Lecture

39 pages

Lecture

Lecture

33 pages

lecture

lecture

54 pages

Lecture

Lecture

30 pages

Exam

Exam

13 pages

Lecture

Lecture

36 pages

Lecture

Lecture

40 pages

Exam

Exam

17 pages

Lecture

Lecture

9 pages

Exam

Exam

15 pages

Lecture

Lecture

44 pages

Lecture

Lecture

34 pages

Lecture

Lecture

24 pages

Lecture

Lecture

29 pages

class12

class12

43 pages

lecture

lecture

43 pages

class22

class22

22 pages

R06-B

R06-B

25 pages

class01b

class01b

19 pages

lecture

lecture

29 pages

lab1

lab1

8 pages

Caches

Caches

36 pages

lecture

lecture

55 pages

Lecture,

Lecture,

37 pages

Integers

Integers

40 pages

Linking

Linking

38 pages

lecture

lecture

45 pages

Lecture

Lecture

61 pages

Linking

Linking

33 pages

lecture

lecture

40 pages

lecture

lecture

40 pages

Lecture

Lecture

32 pages

lecture

lecture

48 pages

lecture

lecture

44 pages

Exam

Exam

11 pages

Lecture

Lecture

31 pages

Lecture

Lecture

46 pages

Lecture

Lecture

40 pages

Lecture

Lecture

40 pages

Exam

Exam

12 pages

Lecture

Lecture

42 pages

Lecture

Lecture

36 pages

Lecture

Lecture

45 pages

Lecture

Lecture

41 pages

Lecture

Lecture

13 pages

Lecture

Lecture

35 pages

Lecture

Lecture

20 pages

Final

Final

19 pages

Lecture

Lecture

33 pages

Lecture

Lecture

50 pages

Lecture

Lecture

33 pages

Lecture

Lecture

27 pages

Lecture

Lecture

6 pages

Exam

Exam

15 pages

Lecture

Lecture

24 pages

Lecture

Lecture

23 pages

Lecture

Lecture

43 pages

Lecture

Lecture

32 pages

Lecture

Lecture

52 pages

Lecture

Lecture

37 pages

Lecture

Lecture

36 pages

Lecture

Lecture

34 pages

Lecture

Lecture

40 pages

Lecture

Lecture

15 pages

lecture

lecture

21 pages

Lecture

Lecture

58 pages

Lecture

Lecture

49 pages

Lecture

Lecture

36 pages

Lecture

Lecture

11 pages

Lecture

Lecture

12 pages

Lecture

Lecture

58 pages

Lecture

Lecture

33 pages

Exam

Exam

15 pages

Lecture

Lecture

35 pages

Lecture

Lecture

10 pages

Lecture

Lecture

25 pages

Lecture

Lecture

31 pages

Lecture

Lecture

24 pages

Lecture

Lecture

34 pages

Lecture

Lecture

50 pages

lecture

lecture

35 pages

Lecture

Lecture

11 pages

Lecture

Lecture

39 pages

Lecture

Lecture

45 pages

Lecture

Lecture

41 pages

exam1-f05

exam1-f05

11 pages

Lecture

Lecture

4 pages

Lecture

Lecture

17 pages

Exam

Exam

17 pages

malloc()

malloc()

12 pages

Lecture

Lecture

57 pages

Lecture

Lecture

30 pages

Lecture

Lecture

30 pages

Lecture

Lecture

47 pages

Lecture

Lecture

33 pages

Exam

Exam

12 pages

Lecture

Lecture

43 pages

Lectures

Lectures

33 pages

Lecture

Lecture

36 pages

lecture

lecture

33 pages

Exam

Exam

14 pages

Lecture

Lecture

43 pages

Lecture

Lecture

25 pages

Load more
Download Recitation
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Recitation and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Recitation and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?