ptr

Bun

Symbol

ptr

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

Get the pointer backing a TypedArray or ArrayBuffer

Use this to pass TypedArray or ArrayBuffer to C functions.

This is for use with FFI functions. For performance reasons, FFI will not automatically convert typed arrays to C pointers.

@param view

the typed array or array buffer to get the pointer for

@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 }