detachZeroCopyPayload function

AdoptedNativePayload? detachZeroCopyPayload(
  1. Uint8List bytes
)

Detaches a zero-copy malloc so another isolate can adopt it.

Returns null when bytes is below the zero-copy floor or has no native backing. The caller must either attachAdoptedNativePayload or releaseAdoptedNativePayload.

Implementation

AdoptedNativePayload? detachZeroCopyPayload(Uint8List bytes) {
  if (bytes.length < zeroCopyResultThresholdBytes) {
    return null;
  }
  final owner = nativeFinalizerOwner(bytes);
  final pointer = nativeBackingPointer(bytes);
  if (owner == null || pointer == null) {
    return null;
  }
  _zeroCopyFinalizer.detach(owner);
  return AdoptedNativePayload(address: pointer.address, length: bytes.length);
}