Memory allocation: Difference between revisions
m
→{{header|Wren}}: Changed to Wren S/H
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
m (→{{header|Wren}}: Changed to Wren S/H) |
||
(5 intermediate revisions by 4 users not shown) | |||
Line 196:
% the memory allocated will now be garbage collected - there is no explicit de-allocation %
end.</syntaxhighlight>
=={{header|Arturo}}==
In Arturo, memory allocation is handled totally and exclusively by the VM, who is responsible for allocating and de-allocatiing memory when no longer needed, via the garbage collector.
The only way a programmer can "allocate" more memory is by flexible structures, like Blocks, and adding more elements to one of the pre-allocated structures:
<syntaxhighlight lang="arturo">
myBlock: @[1 2 3]
'myBlock ++ [4 5 6]
</syntaxhighlight>
=={{header|AutoHotkey}}==
Line 208 ⟶ 219:
The optional second parameter to Buff() allows you to specify the byte to be filled with (default is zero).
=={{header|
===
====Heap====
<syntaxhighlight lang="bbcbasic"> size% = 12345
DIM mem% size%-1
PRINT ; size% " bytes of heap allocated at " ; mem%</syntaxhighlight>
Memory allocated from the heap is only freed on program termination or CLEAR.
====Stack====
<syntaxhighlight lang="bbcbasic"> size% = 12345
PROCstack(size%)
Line 1,085 ⟶ 1,097:
foo_array := Int->New[size]; // allocates an integer array on the heap
x := 0; // allocates an integer on the stack</syntaxhighlight>
=={{header|Odin}}==
<syntaxhighlight lang="odin">package main
import "core:mem"
main :: proc() {
ptr := mem.alloc(1000) // Allocate heap memory
mem.free(ptr)
}</syntaxhighlight>
=={{header|Oforth}}==
Line 1,149 ⟶ 1,172:
=== Heap ===
Their creation and destruction is done explicitly.
<syntaxhighlight lang="pascal">type
Line 1,834 ⟶ 1,857:
The only type of memory allocation where the programmer has any control is the initial number of elements of a List though even here additional elements can be allocated by simply adding them.
<syntaxhighlight lang="
var squares = List.filled(10, 0)
// give them different values and print them
|