Garbage collection; lightstick orientation

Slides:



Advertisements
Similar presentations
PZ10B Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ10B - Garbage collection Programming Language Design.
Advertisements

Lecture 10: Heap Management CS 540 GMU Spring 2009.
Garbage Collection What is garbage and how can we deal with it?
algorithms and data structures
Garbage Collection CSCI 2720 Spring Static vs. Dynamic Allocation Early versions of Fortran –All memory was static C –Mix of static and dynamic.
I. The Problem of Molding Does a given object have a mold from which it can be removed? object not removable mold 1 object removable Assumptions The object.
Polygons and the convex hull Prof. Noah Snavely CS1114
Chapter 8 Runtime Support. How program structures are implemented in a computer memory? The evolution of programming language design has led to the creation.
CS 1114: Data Structures – memory allocation Prof. Graeme Bailey (notes modified from Noah Snavely, Spring 2009)
CS 1114: Data Structures – Implementation: part 1 Prof. Graeme Bailey (notes modified from Noah Snavely, Spring 2009)
Heapsort. 2 Why study Heapsort? It is a well-known, traditional sorting algorithm you will be expected to know Heapsort is always O(n log n) Quicksort.
Finding Red Pixels – Part 2 Prof. Noah Snavely CS1114
Polygons and the convex hull Prof. Noah Snavely CS1114
Linked lists and memory allocation Prof. Noah Snavely CS1114
Voronoi diagrams and applications Prof. Ramin Zabih
Storage Management. The stack and the heap Dynamic storage allocation refers to allocating space for variables at run time Most modern languages support.
Storage allocation issues Prof. Ramin Zabih
Finding Red Pixels Prof. Ramin Zabih
Centroids part 2 Getting rid of outliers and sorting.
Medians and blobs Prof. Ramin Zabih
Representational Art A work of Art that represents an object or subject. For example, any work of art that you can “tell what it is.”
Clustering Prof. Ramin Zabih
University of Washington Wouldn’t it be nice… If we never had to free memory? Do you free objects in Java? 1.
Memory Management -Memory allocation -Garbage collection.
Simulated Pointers Limitations Of C++ Pointers May be used for internal data structures only. Data structure backup requires serialization and deserialization.
CS 1114: Finding things Prof. Graeme Bailey (notes modified from Noah Snavely, Spring 2009)
Graph problems Prof. Ramin Zabih
CS412/413 Introduction to Compilers and Translators April 21, 1999 Lecture 30: Garbage collection.
Recognizing objects Prof. Noah Snavely CS1114
Implementing stacks Prof. Ramin Zabih
Garbage Collection What is garbage and how can we deal with it?
Lightstick orientation; line fitting
Storage 18-May-18.
Prof. Ramin Zabih Implementing queues Prof. Ramin Zabih
Linked Lists in Action Chapter 5 introduces the often-used data public classure of linked lists. This presentation shows how to implement the most common.
Storage Management.
Storage.
CS Introduction to Operating Systems
Simulated Pointers.
Dr. David Matuszek Heapsort Dr. David Matuszek
Craig Schroeder October 26, 2004
The Art Gallery Problem
Data Structures – Stacks and Queus
Memory Management and Garbage Collection Hal Perkins Autumn 2011
Simulated Pointers.
Prof. Ramin Zabih Least squares fitting Prof. Ramin Zabih
Preprocessing to accelerate 1-NN
I. The Problem of Molding
6.2 Grid Search of Chi-Square Space
Heapsort.
Quickselect Prof. Noah Snavely CS1114
Prof. Ramin Zabih Beyond binary search Prof. Ramin Zabih
File-System Structure
Sorting, selecting and complexity
Data Structures and Algorithms
Presentation made by Steponas Šipaila
CS 1114: Introduction to Computing Using MATLAB and Robotics
Heapsort.
Linked lists Prof. Noah Snavely CS1114
Bounding Boxes, Algorithm Speed
CS703 - Advanced Operating Systems
Data Structures and Algorithms
Heapsort.
Garbage collection Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Section
Quicksort and selection
Getting to the bottom, fast
Heapsort.
CO 303 Algorithm Analysis and Design
Garbage Collection What is garbage and how can we deal with it?
Sorting and selection Prof. Noah Snavely CS1114
Presentation transcript:

Garbage collection; lightstick orientation Prof. Ramin Zabih http://cs100r.cs.cornell.edu

Administrivia Assignment 3 is due Friday Prelim on 10/11 Review on Wed 10/10 in section (by Gurmeet) Coverage through Wed 10/10

Manual storage reclamation Programmers always ask for a block of memory of a certain size In C, explicitly declare when it is free Desirable but complex invariants: Everything should be freed when it is no longer going to be used And, it should be freed exactly once! Also want to minimize fragmentation Any serious C programmer writes their own memory allocation system!

Automatic storage reclamation First challenge: figure out what memory locations are in use by the programmer They are the ones that the programmer can get to (i.e., in a linked list currently in use) Anything that has a name the programmer can get to (this is explicit in Matlab) Start with something that has a name, then chase pointers as far as you can go Some programs can access everything… These languages don’t allow such programs!

Root set in Matlab

How to garbage collect? Need to distinguish a value from a pointer Garbage collector doesn’t know anything about the programmer’s data representation Usual solution: use highest-order bit The pointer to location 3 is represented as 2n + 3, where n is usually 31 (word size – 1) Some computers actually had hardware support to tell pointers from values Nice idea that died out in the 90’s

Simple algorithm: mark-sweep Chase the pointers from the root set until you are done Modifying everything as you go (“mark”) Typically, set a bit Everything not marked is garbage, and can go back on the free list Problem: typically a lot more garbage than non-garbage, and need to examine all the garbage with mark-sweep Solutions exist, but are somewhat complex

Back to lightstick shape We have a blob of red pixels Now what? We can easily check which pixels are at the edge of the region How does this help us figure out the shape? Easy solution: build a polygon With a small number of vertices

Convex polygons A polygon is convex if, for any two points A,B in the polygon, all the points between A and B are also in the polygon Corresponds to your intuitive notion of convex More or less… Convex things turn out to matter a lot! A B

Testing convexity How can we test if a polygon P is convex? The obvious way is pretty dumb As is so often the case (in 100R, and in reality) Consider the smallest convex polygon containing P Called the CONVEX HULL What is the convex hull if P is convex?

Convex hull of point sets What is the smallest convex shape containing a bunch of points? I.e., our red pixels? State of the art in lightstick orientation! We still need to compute polygon orientation

Computing convex hull How do we actually compute the convex hull of a set of points? Note that it is easy to identify at least a few points that are part of the convex hull Which ones are they? More precisely, the bounding box is related to the convex hull It touches at 4 points Can it touch at more?

Gift-wrapping algorithm Convex hull: smallest convex polygon containing the points Gift-wrapping: Start at lowest point Find new point such that all the other points lie to the left of the line to it I.e., the largest angle Repeat Figure c/o Craig Gotsman