The following examples will assume the source language is TypeScript, but other source languages will use equivalent semantics for providing memory management constructs.

Pointers

Symbol Usage Notes
type ptr<T> = number & { pointee : T } Symbolic pointer construct  

Addresses

Symbol Usage Notes
addressof<T>(t : T) : ptr<T> Get a pointer to a datum Type parameter is inferred from argument, you do not need to explicitly state it

Dereferencing

Symbol Usage Notes
.pointee : T Dereference a pointer  

Arithmetic

The pointer definition aliases number to allow for direct arithmetic on an instance.

New

For the following object initialization examples we will use a placeholder Foo constructor call for demonstration purposes

Stack Allocation

Symbol Usage Notes
new Foo() : Foo Create a stack allocated instance of Foo Stack allocated memory is deallocated automatically when the enclosing stack frame is popped

Heap Allocation

Symbol Usage Notes
heap(new Foo()) : ptr<Foo> Returns a pointer to a newly heap allocated instance of Foo Heap allocated memory needs to be deleted explicitly

Object Literals

Limited support for object literals exists, and the type must be clearly stated

Symbol Usage Notes
<Foo>{ bar : 1 } Create a stack allocated instance of Foo Foo is inferred from type assertion
f : Foo = { bar : 1 } Create a stack allocated instance of Foo Foo is inferred from left hand side type annotation
{ bar : 1 } as Foo Create a stack allocated instance of Foo Foo is inferred from as expression

Delete

Heap allocated memory should be explicitly deleted using the original pointer returned by heap

Symbol Usage Notes
delete p.pointee Delete the memory pointed to by ptr instance p Must be called on .pointee not p directly

Example