Lecture16-implicit-memory

Lecture16-implicit-memory - Announcements Midterm Oct 25 CS...

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

View Full Document Right Arrow Icon
1 CS 3214 Computer Systems Godmar Back Lecture 16 Announcements • Midterm Oct 25 CS 3214 Fall 2011 2 10/17/2011 Some of the following slides are taken with permission from Complete Powerpoint Lecture Notes for Computer Systems: A Programmer's Perspective (CS:APP) Randal E. Bryant and David R. O'Hallaron http://csapp.cs.cmu.edu/public/lectures.html MEMORY MANAGEMENT Part 2 10/17/2011 CS 3214 Fall 2011 3 Dynamic Memory Allocation Explicit vs. Implicit Memory Allocator Application Dynamic Memory Allocator Heap Memory 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 Allocation – The memory allocator provides an abstraction of memory as a set of blocks or, in type-safe languages, as objects – Doles out free memory blocks to application Will discuss automatic memory allocation today 10/17/2011 4 CS 3214 Fall 2011 Implicit Memory Management • Motivation: manually (or explicitly) reclaiming memory is difficult: – Too early: risk access-after-free errors – Too late: memory leaks • Requires principled design – Programmer must reason about ownership of objects • Difficult & error prone, especially in the presence of object sharing • Complicates design of APIs 10/17/2011 CS 3214 Fall 2011 5 Manual Reference Counting Idea: keep track of how many references there are to each object in a reference counter stored with each object – Copy a reference to an object globalvar = q • increment count: “addref” – Remove a reference p = NULL • decrement count: “release” Uses set of rules programmers must follow E.g., must ‘release’ reference obtained from OUT parameter in function call – Must ‘addref’ when storing into global – May not have to use addref/release for references copied within one function Programmer must use addref/release correctly – Still somewhat error prone, but rules are such that correctness of the code
Background image of page 1

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

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

This note was uploaded on 12/31/2011 for the course CS 3214 taught by Professor Staff during the Fall '11 term at Virginia Tech.

Page1 / 5

Lecture16-implicit-memory - Announcements Midterm Oct 25 CS...

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

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