Memory allocation: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
(added Arturo implementation)
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(2 intermediate revisions by 2 users not shown)
Line 201:
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">
Line 219:
The optional second parameter to Buff() allows you to specify the byte to be filled with (default is zero).
 
=={{header|BBC BASIC}}==
===Heap{{header|BBC BASIC}}===
====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,856 ⟶ 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="ecmascriptwren">// create a list with 10 elements all initialized to zero
var squares = List.filled(10, 0)
// give them different values and print them
9,479

edits