L06-ac-memmgmt-intromips

L06-ac-memmgmt-intromips - inst.eecs.berkeley.edu/~cs61c...

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

View Full Document Right Arrow Icon
CS61C L06 More Memory Management, Intro to MIPS (1) Chae, Summer 2008 © UCB Albert Chae, Instructor inst.eecs.berkeley.edu/~cs61c CS61C : Machine Structures Lecture 6 – Garbage Collection, Intro to MIPS 2008-07-01
Background image of page 1

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

View Full Document Right Arrow Icon
CS61C L06 More Memory Management, Intro to MIPS (2) Chae, Summer 2008 © UCB Revie w C has 3 pools of memory Static storage : global variable storage, basically permanent, entire program run The Stack : local variable storage, parameters, return address The Heap (dynamic storage): malloc() grabs space from here, free() returns it. malloc() handles free space with freelist. Three different ways to find free space when given a request: First fit (find first one that’s free) Next fit (same as first, but remembers where left off) Best fit (finds most “snug” free space)
Background image of page 2
CS61C L06 More Memory Management, Intro to MIPS (3) Chae, Summer 2008 © UCB Revie w Different ways to manage freelist Slab allocator Buddy system No single one is best! Depends on program. Internal vs External fragmentation Automatic memory management? Garbage collection!
Background image of page 3

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

View Full Document Right Arrow Icon
CS61C L06 More Memory Management, Intro to MIPS (4) Chae, Summer 2008 © UCB Automatic Memory Management Dynamically allocated memory is difficult to track – why not track it automatically ? If we can keep track of what memory is in use, we can reclaim everything else. Unreachable memory is called garbage , the process of reclaiming it is called garbage collection . So how do we track what is in use?
Background image of page 4
CS61C L06 More Memory Management, Intro to MIPS (5) Chae, Summer 2008 © UCB Tracking Memory Usage Techniques depend heavily on the programming language and rely on help from the compiler. Start with all pointers in global variables and local variables ( root set ). Recursively examine dynamically allocated objects we see a pointer to. We can do this in constant space by reversing the pointers on the way down How do we recursively find pointers in dynamically allocated memory?
Background image of page 5

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

View Full Document Right Arrow Icon
CS61C L06 More Memory Management, Intro to MIPS (6) Chae, Summer 2008 © UCB Tracking Memory Usage Again, it depends heavily on the programming language and compiler. Could have only a single type of dynamically allocated object in memory E.g., simple Lisp/Scheme system with only cons cells (61A’s Scheme not “simple”) Could use a strongly typed language (e.g., Java) Don’t allow conversion (casting) between arbitrary types. C/C++ are not strongly typed. Here are 3 schemes to collect garbage
Background image of page 6
L06 More Memory Management, Intro to MIPS (7) Chae, Summer 2008 © UCB Scheme 1: Reference Counting For every chunk of dynamically allocated memory, keep a count of number of pointers that point to it. When the count reaches 0, reclaim.
Background image of page 7

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

View Full Document Right Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 43

L06-ac-memmgmt-intromips - inst.eecs.berkeley.edu/~cs61c...

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

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