Memory allocation: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 829: | Line 829: | ||
Like Perl 5, Perl 6 is intended to run largely stackless, so all allocations are really on the heap, including activation records. Allocations are managed automatically. It is easy enough to allocate a memory buffer of a particular size however, if you really need it: |
Like Perl 5, Perl 6 is intended to run largely stackless, so all allocations are really on the heap, including activation records. Allocations are managed automatically. It is easy enough to allocate a memory buffer of a particular size however, if you really need it: |
||
<lang perl6>my $buffer = Buf.new(0 xx 1024);</lang> |
<lang perl6>my $buffer = Buf.new(0 xx 1024);</lang> |
||
=={{header|Phix}}== |
|||
In normal use, memory management is fully automatic in Phix. However you may need to explicitly allocate memory when interfacing to C etc. |
|||
By default (for compatibility with legacy code) cleanup must be performed manually, but there is an optional flag on both the memory |
|||
allocation routines (allocate and allocate_string) to automate that for you, or you could even roll your own via delete_routine(). |
|||
<lang Phix>atom addr = allocate(512) -- limit is 1,610,612,728 bytes on 32-bit systems |
|||
... |
|||
free(addr) |
|||
atom addr2 = allocate(512,1) -- automatically freed when addr2 drops out of scope |
|||
atom addr3 = allocate_string("a string",1) -- automatically freed when addr3 drops out of scope</lang> |
|||
Behind the scenes, the Phix stack is actually managed as a linked list of virtual stack blocks allocated on the heap, and as such it |
|||
would be utterly pointless and quite probably extremely tricky to mess with. |
|||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |
||
Only the heap can be explicitly controlled in PicoLisp. Usually this is not necessary, as it happens automatically. |
Only the heap can be explicitly controlled in PicoLisp. Usually this is not necessary, as it happens automatically. |