Memory allocation: Difference between revisions

Added Wren
m (Added Delphi reference to Pascal code)
(Added Wren)
Line 1,691:
* Using <code>string repeat</code> or <code>lrepeat</code> to make a group of entities that work like a block of memory (despite not being); these need marshalling code to bridge to foreign function interfaces.
* Using [[:Category:SWIG|SWIG]] or [[:Category:critcl|critcl]] to write a bridge to a standard [[C]] allocator.
 
=={{header|Wren}}==
In Wren memory for any object is allocated automatically by the VM and de-allocated automatically when there are no longer any references to it by the garbage collector.
 
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.
<lang ecmascript>// create a list with 10 elements all initialized to zero
var squares = List.filled(10, 0)
// give them different values and print them
for (i in 0..9) squares[i] = i * i
System.print(squares)
// add another element to the list dynamically and print it again
squares.add(10 * 10)
System.print(squares)
squares = null // make eligible for GC </lang>
 
{{out}}
<pre>
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
</pre>
 
=={{header|X86 Assembly}}==
9,488

edits