May. 15th, 2012

tim: Tim with short hair, smiling, wearing a black jacket over a white T-shirt (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 with short hair, smiling, wearing a black jacket over a white T-shirt (Default)
Tim Chevalier

November 2021

S M T W T F S
 123456
78 910111213
14151617181920
21222324252627
282930    

Most Popular Tags

Page Summary

Style Credit

Expand Cut Tags

No cut tags