Arena<T extends NativeType> class

Instead of doing many little allocations, Arena allocates a large chunk of memory which can be sliced into multiple Arrays. When all operations have finished, the Arena can be deleted and it frees all memory in one operation. This can significantly improve performance and it makes memory management simpler when dealing with many allocations.

final arena = Arena<Uint8>(10, Uint8Array.fromPtr);
final array = arena.newArray(5);
final array2 = arena.newArray(5);
void some_native_c_api(array.ptr, array.view.length, array2.ptr, array2.view.length);
arena.delete();
Available Extensions

Constructors

Arena(int length, Array<T> _arrayFromPtr(Pointer<T>, int))
_arrayFromPtr constructs a new Array with length elements
Arena.fromPtr(Pointer<T> _arrPtr, int length, Array<T> _arrayFromPtr(Pointer<T>, int))
_arrPtr points to a pre-allocated array of length.

Properties

freeSpace → int
Left free space of Arena.
read-only
length → int
Total length of allocated memory
final
hashCode → int
The hash code for this object. [...]
read-only, inherited
runtimeType → Type
A representation of the runtime type of the object.
read-only, inherited

Methods

delete() → void
Deletes all allocated memory.
newArray(int length) Array<T>
Returns a slice of length elements from the pre-allocated array of Arena. When length exceeds freeSpace it throws a RangeError.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
toString() → String
Returns a string representation of this object.
inherited

Operators

operator ==(dynamic other) → bool
The equality operator. [...]
inherited