Difference between revisions of "Heap"
From Mesham
Jump to navigationJump to searchm |
|||
Line 19: | Line 19: | ||
[[Category:Type Library]] | [[Category:Type Library]] | ||
− | [[Category: | + | [[Category:Compound Types]] |
[[Category:Allocation Types]] | [[Category:Allocation Types]] |
Revision as of 17:52, 12 January 2013
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 |