node-ctypes - v2.10.0
    Preparing search index...

    Interface PointerInstance<T>

    A pointer instance created by PointerTypeDef.create, PointerTypeDef.fromBuffer, or PointerTypeDef.fromAddress.

    Supports Python ctypes-compatible .contents property and C-like [index] pointer arithmetic.

    const IntPtr = POINTER(c_int32);
    const p = IntPtr.fromBuffer(buf);
    console.log(p.contents.value); // dereferenced value (like *p in C)
    console.log(p[0]); // same as p.contents
    console.log(p[5]); // pointer arithmetic (like p[5] in C)
    // When a struct has a c_void_p field pointing to an array of structs:
    const pValues = POINTER(ADSVALUE).fromAddress(col.pADsValues);
    for (let i = 0; i < col.dwNumValues; i++) {
    console.log(pValues[i].dwType); // struct view at pValues + i * sizeof(ADSVALUE)
    }
    interface PointerInstance<T = any> {
        _pointerType: PointerTypeDef<T>;
        _baseType: AnyType | StructDef<Record<string, any>>;
        _baseSize: number;
        address: bigint;
        get contents(): PointerContents<T>;
        set contents(value: PointerContents<T> | JsArgFromCType<T>): void;
        _buffer: Buffer<ArrayBufferLike>;
        deref(): PointerContents<T>;
        set(value: number | bigint | Buffer<ArrayBufferLike>): void;
        isNull: boolean;
        toBuffer(): Buffer;
        toString(): string;
        add(n: number): PointerInstance<T>;
        slice(start: number, end: number): PointerValue<T>[];
        [index: number]: PointerValue<T>;
    }

    Type Parameters

    • T = any

    Indexable

    • [index: number]: PointerValue<T>

      Pointer arithmetic — access elements at offset from the pointer.

      p[i] reads sizeof(baseType) bytes at address + i * sizeof(baseType), exactly like C pointer indexing.

      const arr = POINTER(c_int32).fromAddress(arrayAddr);
      arr[0] // first element
      arr[5] // sixth element
      arr[2] = 99; // write to third element
    Index
    _pointerType: PointerTypeDef<T>

    The pointer type definition this instance was created from.

    _baseType: AnyType | StructDef<Record<string, any>>

    The base type this pointer points to.

    _baseSize: number

    Size of the pointed-to type in bytes.

    address: bigint

    Raw memory address as BigInt.

    _buffer: Buffer<ArrayBufferLike>

    The underlying buffer (if created from a buffer), or null.

    isNull: boolean

    Check if this is a NULL pointer.

    • get contents(): PointerContents<T>

      The pointed object, as Python's p.contents: a live instance on the pointed memory (p.contents.value for simple types, p.contents.x for structures). Assigning an instance re-points the pointer to it; assigning a plain value writes it.

      Returns PointerContents<T>

      const p = POINTER(c_int32).fromBuffer(buf);
      console.log(p.contents.value); // read value
      p.contents = 42; // write value
      p.contents = new c_int32(7); // re-point
    • set contents(value: PointerContents<T> | JsArgFromCType<T>): void

      Parameters

      Returns void

    • Set pointer to a new target (buffer or address).

      Parameters

      • value: number | bigint | Buffer<ArrayBufferLike>

        Buffer to point to, or BigInt/number address

      Returns void

    • Get pointer as an 8-byte buffer containing the address.

      Returns Buffer

    • Read end - start consecutive elements into a JS array, analogous to Python's p[start:end] on a POINTER(T).

      Parameters

      • start: number
      • end: number

      Returns PointerValue<T>[]