function

ffi.ptr

function ptr(
view: ArrayBufferLike | TypedArray<ArrayBufferLike> | DataView<ArrayBufferLike>,
byteOffset?: number

Get the pointer backing a TypedArray or ArrayBuffer

Use this to pass a TypedArray or ArrayBuffer to a C function. For performance reasons, FFI does not convert typed arrays to C pointers automatically.

@param view

The typed array, ArrayBuffer, or DataView to get the pointer of

@param byteOffset

Optional offset into the view, in bytes

From JavaScript:

const array = new Uint8Array(10);
const rawPtr = ptr(array);
myFFIFunction(rawPtr);

To C:

void myFFIFunction(char* rawPtr) {
 // Do something with rawPtr
}

Referenced types

type Pointer = number & { __pointer__: null }