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…') |
m (6 revisions imported) |
||
(5 intermediate revisions by the same user not shown) | |||
Line 10: | Line 10: | ||
== Example == | == Example == | ||
− | var i:Int :: allocated[heap]; | + | function void main() { |
+ | 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. | 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. | ||
+ | |||
+ | ''Since: Version 1.0'' | ||
+ | |||
+ | == Default allocation strategies == | ||
+ | |||
+ | {{Template:DefaultMemoryAllocation}} | ||
[[Category:Type Library]] | [[Category:Type Library]] | ||
− | [[Category: | + | [[Category:Compound Types]] |
[[Category:Allocation Types]] | [[Category:Allocation Types]] |
Latest revision as of 15:44, 15 April 2019
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
function void main() { 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.
Since: Version 1.0
Default allocation strategies
Type | Default allocation strategy |
---|---|
All element types | Stack |
Array | Heap |
Record | Stack |
Reference record | Heap |