Arena<T extends NativeType, L extends List<int>> class

Instead of doing many little allocations / deallocations, Arena allocates / deallocates a large chunk of memory for multiple pointers / arrays, which can improve performance and makes memory management simpler.

Note: Don't free slices of Arena manually. Only call delete after you are done with all slices. Using slices after deleting Arena leads to undefined behaviour. Not deleting Arena will cause a memory leak.

final arena = Arena<Uint8,Uint8List>(10, (ptr, length) => ptr.asTypedList(length));
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();
Implementers

Constructors

Arena(int length, L _getView(Pointer<T>, int))
length of allocated memory. _getView returns the associated typed list for Pointer<T>.
Arena.fromPtr(Pointer<T> _arrPtr, int length, L _getView(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, L>
Returns a slice of length 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