SharedArray<T extends NativeType> class
Instead of allocating many arrays, share one array which gets deleted when all references to it got deleted. This can lead to better performance and reduced memory usage.
Gets lazily initialized when the first reference gets created. It is safe to use even after deletion; it just reallocates new memory for new references. Not deleting all references causes memory leaks.
final shared = SharedUint8Array<Uint8>(10);
// All instances of [WritesToArray] share the same [SharedArray] so they don't have to all
// allocate their own array.
class WritesToArray {
final _buffer = shared.newRef();
Uint8List someNativeWrapper(){
writeToBuffer(_buffer.ptr);
return Uint8List.fromList(_buffer.view);
}
void delete() => _buffer.delete();
}
- Available Extensions
Constructors
-
_allocateArray
allocates an Array oflength
elements
Properties
Methods
-
newRef(
) → ArrayRef< T> -
Create new reference to this SharedArray.
@mustCallSuper
-
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 ==(
Object other ) → bool -
The equality operator. [...]
inherited