NativeBufferAllocator constructor
NativeBufferAllocator(
- DynamicLibrary library
Borrows a library that the caller must keep loaded for process lifetime. Closing/reloading it invalidates callback addresses and is unsupported. Prefer NativeBufferAllocator.instance for the managed runtime library.
Implementation
NativeBufferAllocator(ffi.DynamicLibrary library) {
const symbols = [
'ct_owned_buffer_abi_version',
'ct_owned_buffer_allocate',
'ct_owned_buffer_info',
'ct_owned_buffer_freeze',
'ct_owned_buffer_slice',
'ct_owned_buffer_release',
'ct_owned_buffer_handle_finalizer',
'ct_owned_buffer_export',
'ct_owned_buffer_view_finalizer',
'ct_owned_buffer_send',
];
if (!symbols.every(library.providesSymbol)) return;
final version = library.lookupFunction<_VersionN, _VersionD>(symbols[0]);
if (version() != 1) return;
_identity = library
.lookup<ffi.NativeFunction<_VersionN>>(symbols[0])
.address;
_allocate = library.lookupFunction<_AllocateN, _AllocateD>(symbols[1]);
_info = library.lookupFunction<_InfoN, _InfoD>(symbols[2]);
_freeze = library.lookupFunction<_RangeN, _RangeD>(symbols[3]);
_slice = library.lookupFunction<_RangeN, _RangeD>(symbols[4]);
_release = library.lookupFunction<_ReleaseN, _ReleaseD>(symbols[5]);
_handleFinalizer = _libraryFinalizers.putIfAbsent(
_identity,
() => ffi.NativeFinalizer(
library.lookup<ffi.NativeFinalizerFunction>(symbols[6]),
),
);
_export = library.lookupFunction<_ExportN, _ExportD>(symbols[7]);
_viewFinalizer = library.lookup<ffi.NativeFinalizerFunction>(symbols[8]);
_freeView = _viewFinalizer
.asFunction<void Function(ffi.Pointer<ffi.Void>)>();
_send = library.lookupFunction<_SendN, _SendD>(symbols[9]);
_supported = true;
_loadExternalTokens(library);
_loadWriteCompletion(library);
_loadOwnedE2eeEncryption(library);
_frames = _NativeFrameApi.load(this, library);
_segments = _NativeOwnedSegmentsApi.load(this, library);
}