SharedArray<T extends NativeType, L extends List<int> > class
Instead of allocating / deallocating 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 = SharedArray<Uint8,Uint8List>(10, (ptr,len) => ptr.asTypedList(len));
// 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();
}
- Implementers
Constructors
Properties
- length → int
-
final
- refCount → int
-
read-only
- 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
-
newRef(
) → ArrayRef< T, L> - Create new reference to this SharedArray.
-
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