Function ptr

  • 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.

    Example

    From JavaScript:

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

    To C:

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

    Parameters

    • view: TypedArray | ArrayBufferLike | DataView

      the typed array or array buffer to get the pointer for

    • Optional byteOffset: number

      optional offset into the view in bytes

    Returns number

  • 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.

    Example

    From JavaScript:

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

    To C:

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

    Parameters

    • view: TypedArray | ArrayBufferLike | DataView

      the typed array or array buffer to get the pointer for

    • Optional byteOffset: number

      optional offset into the view in bytes

    Returns number

Generated using TypeDoc