lec8 - Lecture 8 Dynamic Memory Allocation CS240 1...

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

View Full Document Right Arrow Icon
Lecture 8 Dynamic Memory Allocation CS240 1 Wednesday, February 9, 2011
Background image of page 1

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

View Full DocumentRight Arrow Icon
Memory Computer programs manipulate an abstraction of the computer’s memory subsystem Wednesday, February 9, 2011
Background image of page 2
Memory: on the hardware side 3 @ http://computer.howstuffworks.com/computer-memory.htm/printable Wednesday, February 9, 2011
Background image of page 3

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

View Full DocumentRight Arrow Icon
Memory: on the software side 4 Each computer programming languages offers a different abstraction The goal is to make programming easier and improve portability of the source code by hiding irrelevant hardware oddities Each language offers a memory API -- a set of operations for manipulating memory Sample exam question: - How does the abstraction of memory exposed by the Java programming language differ from that of the C programming language? Wednesday, February 9, 2011
Background image of page 4
Memory: the Java Story Memory is a set of objects with Felds, methods and a class + local variables of a method Memory is read by accessing a Feld or local variable Memory is modiFed by writing to a Feld or local variable Location and size of data are not exposed Memory allocation is done by call in new Question: - Does main() terminate? 5 while ( true ) { c 1 = new Cell(); c 2 = c 1 ; class Cell { Cell next ; } Wednesday, February 9, 2011
Background image of page 5

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

View Full DocumentRight Arrow Icon
Memory: the Java Story Memory is a set of objects with Felds, methods and a class + local variables of a method Memory is read by accessing a Feld or local variable Memory is modiFed by writing to a Feld or local variable Location and size of data are not exposed Memory allocation is done by call in new Question: - Does main() terminate? 6 while ( true ) { c 1 = new Cell(); c 1 . next = c2; c 2 = c 1 ; } } } class Cell { Cell next ; } Wednesday, February 9, 2011
Background image of page 6
Memory: the Java Story The semantics of new is as follows: Allocate space for the object’s Felds and metadata Felds Initialize the metadata Felds Set all Felds to null/zero/false Invoke the user deFned constructor method 7 Heap next felds metadata hash lock class + methods Wednesday, February 9, 2011
Background image of page 7

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

View Full DocumentRight Arrow Icon
Aparté Garbage collection is the technology that gives the illusion of inFnite resources Garbage collection or GC is implemented by the programming language with the help of the compiler Though for a some well-behaved C programs it is possible to link a special library that provides most of the beneFts of GC Question: - How does GC work? 8 Wednesday, February 9, 2011
Background image of page 8
Garbage Collection thread#2 thread#1 heap Phases Mutation Wednesday, February 9, 2011
Background image of page 9

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

View Full DocumentRight Arrow Icon
Garbage Collection thread#2 thread#1 heap Phases Mutation Wednesday, February 9, 2011
Background image of page 10
Garbage Collection thread#2 thread#1 heap Phases Mutation Wednesday, February 9, 2011
Background image of page 11

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

View Full DocumentRight Arrow Icon
Garbage Collection thread#2 thread#1 heap Phases Mutation Stop-the-world Wednesday, February 9, 2011
Background image of page 12
Garbage Collection thread#2 thread#1 heap Phases Mutation Stop-the-world Wednesday, February 9, 2011
Background image of page 13

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

View Full DocumentRight Arrow Icon
Garbage Collection thread#2 thread#1 heap Phases Mutation Stop-the-world Wednesday, February 9, 2011
Background image of page 14
Garbage Collection thread#2 thread#1 heap Phases Mutation Stop-the-world Root scanning Marking Sweeping Compaction Wednesday, February 9, 2011
Background image of page 15

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

View Full DocumentRight Arrow Icon
Image of page 16
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 47

lec8 - Lecture 8 Dynamic Memory Allocation CS240 1...

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

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