next up previous contents index
Next: Garbage collection Up: Algebraic Datatypes and Previous: Refining a datatype

Memory management

By default, a datatype constructor calls the operator new to allocated memory. There are a few ways to change this behavior: (i) redefine the operator new within the datatype using refinement; or (ii) inherit from a class that redefines this method.

If a placement operator new is defined in datatype, the placement constructor syntax can be used to invoke this operator:


Placement_Cons ::=Cons '( Exp, ¼ , Exp ) ( [ Exp, ¼ , Exp ] )
  |  Cons '( Exp, ¼ , Exp ) { [ Id = Exp, ¼ , Id = Exp ] }

For example, in the following the extra parameter mem will be passed to placement new operator.

  Exp e1 = INT'(mem)(1);
  Exp e2 = VAR'(mem){ name = "foo", typ = t };





Allen Leung
Mon Apr 7 14:33:55 EDT 1997