Heap

From Mesham
Revision as of 16:57, 12 January 2013 by Polas (talk | contribs)
Jump to navigationJump to search

Syntax

heap[]

Semantics

Instructs the environment to bind the associated variable to heap memory which exists regardless of runtime context.

Note: All heap memory is garbage collected. The specifics of this depends on the runtime library, broadly when it goes out of scope then it will be collected at some future point. Although not nescesary, you can assign the null value to the variable which will drop a reference to the memory. Note: This type, used for function parameters or return type instructs pass by reference

Example

var i:Int :: allocated[heap];

In this example variable i is declared as an integer and allocated to all processes (by default) and also on the heap. Note how we have omitted the optional braces to the stack type as there are no arguments.

Default allocation strategies

Type Default allocation strategy
All element types Stack
Array Heap
Record Stack
Reference record Heap