Memory package - Manhunter07/MFL GitHub Wiki
Notice: This object is deprecated and should only be used if needed or for backward compatibility
The memory package (namely, Memory
package) was a first attempt to implement dynamic memory allocation in MFL. It was designed as a workaround until real structures (strings, arrays and records) would have been ready for use. The package allowed the allocation, reading, writing and freeing of memory storing numeric values. It acted like a virtual heap that mapped its allocated areas onto a hard-coded dictionary class that stores the memory in blocks. Note that each block stands for itself and cannot overlap with other blocks. Leaving the sope of a block will raise an exception rather than smoothly enter the previous/next one.
Although still functional, this package has not been worked on nor optimized to run on current compiler versions and has been removed from default compilations. You can still manually add it when needed however.
Members
The memory package is a stateful package containing the following objects:
Nil
const Nil = 0
Represents an empty offset (namely, 0
) for empty, invalid or unassigned addresses.
Address
type Address = rangeint(Memory.Nil, System.Inf)
Supports any integer value that can be a valid memory address. This ranges from Memory.Nil
(see above) to System.Inf
.
Size
type Size = rangeint(Memory.Nil, System.Inf)
Supports any integer value that can represent a valid range size. This can be anything between 0
and System.Inf
.
Clear
function Clear = \built-in\
Returns the allocated size (see Memory.Size
below) of the memory and frees all blocks afterwards.
Alloc
function Alloc(Size: Memory.Size) = \built-in\
Allocates a new memory block with a specified size and returns its address.
Realloc
function Realloc(Address: Memory.Address, Size: Memory.Size) = \built-in\
Reallocates the specified memory block with a new size. Previous data stored in that block will be reset to 0
. The function always returns 0
.
Free
function Free(Address: Memory.Address) = \built-in\
Frees the specified memory block by deleting it and returns its previous size.
Read
function Read(Address & Index: Memory.Address) = \built-in\
Returns the value stored at the speficied address and the specified index.
Write
function Write(Address & Index: Memory.Address, Value &&: Number) = \built-in\
Stores the value in the specified block at the specified index. The function always returns 0
.