May. 15th, 2012

tim: Tim wearing a flannel shirt, against a brick wall (working)

Yesterday and today, I worked on adding destructors to classes. A destructor is a method that can't be named directly, to which the compiler inserts a call whenever the memory for the class is about to be freed (so, whenever its reference count becomes zero). Here's a super simple example of a class with a destructor:

class shrinky_pointer {
  let i: @@mut int;
  fn look_at() -> int { ret **(self.i); }
  new(i: @@mut int) { self.i = i; }
  drop { **(self.i) -= 1; }
}
Read more... )

Profile

tim: Tim wearing a flannel shirt, against a brick wall (Default)
Tim Chevalier

May 2013

S M T W T F S
   1 2 3 4
567 8 9 1011
1213 14 15 161718
19 20 21 22 23 2425
262728293031 

Most Popular Tags

Page Summary

Style Credit

Style:
Yvonne

Expand Cut Tags

No cut tags