Class 9: Pointers in Rust

Posted: Tue 18 February 2014

Problem Set 3 is due on Monday, 3 March. Everyone should have a team formed for PS3 now and be making progress on it soon!

Thursday's class will be a project work day. Take advantage of this opportunity to coordinate with your team and make progress on PS3. (Dave is out of town Wednesday-Friday. Several of the TAs will come to class Thursday and be available to help with PS3.)

Unmanaged vs. Managed Memory Management

What does it mean for a programming language to have unmanaged memory?

What are different ways to provide management memory?

Type Safety and Garbage Collection

Why is it hard to provide automatic memory management in a language that is not type-safe?

Garbage collection for C: Hans-J. Boehm, Simple Garbage-Collector-Safety, PLDI 1996. Latest version: https://github.com/ivmai/bdwgc/.

What are the advantages and disadvantages of reference counting compare to mark-and-sweep garbage collection?

Systematic Memory Management

Paper on willy-nilly memory management: Static Detection of Dynamic Memory Errors (PLDI 1996). The Splint tool is available from http://www.splint.org.

Pointers in Rust

What does it mean to borrow an object?

What restrictions should there be on what code can do with borrowed objects and why?

What is wrong with this code?

fn main() {
   let ref stolen : ~str;

   {
      let mine: ~str = ~"Mine, all mine!";
      stolen = &mine;
   }    

   println!("Whose is it? {:s}", *stolen);
}

How does this code establish the lifetime of the result?

fn bigger<'a>(s1: &'a str, s2: &'a str) -> &'a str {
    if s1.len() > s2.len() { s1 } else { s2 }
}

Problem Set 3

You should have your team formed for PS3 now. If you are having trouble forming a team, make sure I know about it by the end of today.

Les noms zepto et zetta évoquent le chiffre sept (septième puissance de 103) et la lettre « z » remplace la lettre « s » pour éviter le double emploi de la lettre « s » comme symbole. Les noms yocto et yotta sont dérivés de octo, qui évoque le chiffre huit (huitième puissance de 103) ; la lettre « y » est ajoutée pour éviter l'emploi de la lettre « o » comme symbole à cause de la confusion possible avec le chiffre zéro.

Résolution 4 de la 19e réunion de la CGPM (1991) (Unofficial English version). (Note that I am leaving room for one of you to produce a Yohtta server.)

comments powered by Disqus