jlbun
    Preparing search index...

    Class JuliaPtr

    Wrapper for Julia Ptr{T} - typed pointer for FFI and memory operations.

    Julia's Ptr{T} is used for:

    • C interoperability (ccall)
    • Direct memory access
    • Array data pointers

    Operations like load() and store() are unsafe - they can cause segfaults or memory corruption if used incorrectly. The caller is responsible for ensuring:

    • The pointer is valid and properly aligned
    • The pointed-to memory has not been freed
    • The type matches the actual data in memory
    // Get pointer to array data
    const arr = JuliaArray.from(new Float64Array([1, 2, 3]));
    const ptr = JuliaPtr.fromArray(arr);

    // Read values (unsafe_load)
    const first = ptr.load(); // 1.0
    const second = ptr.load(1); // 2.0 (offset by 1 element)

    // Write values (unsafe_store!)
    ptr.store(99.0, 0); // arr[0] = 99.0

    // Pointer arithmetic
    const ptr2 = ptr.offset(2); // Points to arr[2]

    Hierarchy

    • JuliaPrimitive
      • JuliaPtr
    Index

    Constructors

    Properties

    ptr: Pointer

    Accessors

    • get address(): bigint

      Get the raw address value of this pointer.

      Returns bigint

      The memory address as a bigint.

    • get isNull(): boolean

      Check if this is a null pointer (C_NULL).

      Returns boolean

    • get value(): Pointer

      Get the raw pointer value (same as address but as Bun's Pointer type).

      Returns Pointer

    Methods

    • Load a value from the pointer location. Equivalent to Julia's unsafe_load(ptr, i).

      WARNING: This is an unsafe operation!

      Parameters

      • offset: number = 0

        Element offset (0-based, default 0). Offset is in units of the element type size, not bytes.

      Returns JuliaValue

      The value at the pointer location.

    • Create a new pointer offset by n elements.

      Note: Julia's ptr + n offsets by n bytes. This method offsets by n elements (n * sizeof(T) bytes) for more intuitive usage.

      Parameters

      • n: number

        Number of elements to offset (can be negative).

      Returns JuliaPtr

      A new JuliaPtr pointing to the offset location.

    • Reinterpret this pointer as a different type. Equivalent to reinterpret(Ptr{T}, ptr) in Julia.

      Parameters

      • newElType: JuliaValue

        The new element type (e.g., Julia.Float64).

      Returns JuliaPtr

      A new JuliaPtr with the reinterpreted type.

    • Store a value at the pointer location. Equivalent to Julia's unsafe_store!(ptr, value, i).

      WARNING: This is an unsafe operation!

      Parameters

      • value: string | number | bigint | boolean | JuliaValue

        The value to store.

      • offset: number = 0

        Element offset (0-based, default 0). Offset is in units of the element type size, not bytes.

      Returns void

    • Returns string

    • Create a Ptr{Cvoid} from a raw address.

      Parameters

      • address: number | bigint

        The memory address as a number or bigint.

      Returns JuliaPtr

      A new JuliaPtr pointing to the address.

      const ptr = JuliaPtr.fromAddress(0x7fff12340000n);
      
    • Get the data pointer from a JuliaArray.

      Parameters

      Returns JuliaPtr

      A JuliaPtr pointing to the array's data.

      const arr = JuliaArray.from(new Float64Array([1, 2, 3]));
      const ptr = JuliaPtr.fromArray(arr);
    • Get the memory address of any Julia object.

      WARNING: The returned pointer is only valid while the object is protected from garbage collection! Use with extreme caution.

      Parameters

      Returns JuliaPtr

      A JuliaPtr pointing to the object's memory location.