Difference between revisions of "Heap"
From Mesham
Jump to navigationJump to search (Created page with '== Syntax == heap[] == Semantics == Instructs the environment to bind the associated variable to heap memory which exists regardless of runtime context.<br><br> ''Note:'' All h…') |
|||
Line 13: | Line 13: | ||
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. | 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 == | ||
+ | |||
+ | {{Template:DefaultMemoryAllocation}} | ||
[[Category:Type Library]] | [[Category:Type Library]] | ||
[[Category:Composite Types]] | [[Category:Composite Types]] | ||
[[Category:Allocation Types]] | [[Category:Allocation Types]] |
Revision as of 16:57, 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 |