Class DirectMemoryIO

Direct Known Subclasses:
AllocatedDirectMemoryIO, TransientNativeMemory

class DirectMemoryIO extends AbstractMemoryIO
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    (package private) static final com.kenai.jffi.MemoryIO
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    DirectMemoryIO(Runtime runtime, int address)
     
    DirectMemoryIO(Runtime runtime, long address)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the array that backs this pointer.
    int
    Returns the length of this pointer's backing array that is used by this pointer.
    int
    Returns the offset within this pointer's backing array of the first element.
    boolean
     
    final void
    get(long offset, byte[] dst, int off, int len)
    Bulk get method for multiple byte values.
    final void
    get(long offset, double[] dst, int off, int len)
    Bulk get method for multiple double values.
    final void
    get(long offset, float[] dst, int off, int len)
    Bulk get method for multiple float values.
    final void
    get(long offset, int[] dst, int off, int len)
    Bulk get method for multiple int values.
    final void
    get(long offset, long[] dst, int off, int len)
    Bulk get method for multiple long values.
    final void
    get(long offset, short[] dst, int off, int len)
    Bulk get method for multiple short values.
    final byte
    getByte(long offset)
    Reads an byte (8 bit) value at the given offset.
    final double
    getDouble(long offset)
    Reads a double (64 bit) value at the given offset.
    final float
    getFloat(long offset)
    Reads a float (32 bit) value at the given offset.
    final int
    getInt(long offset)
    Reads an int (32 bit) value at the given offset.
    final long
    getLongLong(long offset)
    Reads a long (64 bit) value at the given offset.
    getPointer(long offset)
    Reads an Pointer value at the given offset.
    getPointer(long offset, long size)
    Reads an Pointer value at the given offset.
    final short
    getShort(long offset)
    Reads a short (16 bit) value at the given offset.
    getString(long offset)
    Reads an String value at the given offset.
    getString(long offset, int maxLength, Charset cs)
    Reads a String value at the given offset, using a specific Charset
    boolean
    Indicates whether this Pointer instance is backed by an array.
    int
     
    int
    indexOf(long offset, byte value, int maxlen)
    Returns the location of a byte value within the memory area represented by this Pointer.
    private static void
    memcpy(DirectMemoryIO src, long srcOffset, DirectMemoryIO dst, long dstOffset, long count)
     
    final void
    put(long offset, byte[] src, int off, int len)
    Bulk put method for multiple byte values.
    final void
    put(long offset, double[] src, int off, int len)
    Bulk put method for multiple double values.
    final void
    put(long offset, float[] src, int off, int len)
    Bulk put method for multiple float values.
    final void
    put(long offset, int[] src, int off, int len)
    Bulk put method for multiple int values.
    final void
    put(long offset, long[] src, int off, int len)
    Bulk put method for multiple long values.
    final void
    put(long offset, short[] src, int off, int len)
    Bulk put method for multiple short values.
    final void
    putByte(long offset, byte value)
    Writes a byte (8 bit) value at the given offset.
    final void
    putDouble(long offset, double value)
    Writes a double (64 bit, double precision) value at the given offset.
    final void
    putFloat(long offset, float value)
    Writes a float (32 bit, single precision) value at the given offset.
    final void
    putInt(long offset, int value)
    Writes an int (32 bit) value at the given offset.
    final void
    putLongLong(long offset, long value)
    Writes a long (64 bit) value at the given offset.
    void
    putPointer(long offset, Pointer value)
    Writes a Pointer value at the given offset.
    final void
    putShort(long offset, short value)
    Writes a short (16 bit) value at the given offset.
    void
    putString(long offset, String string, int maxLength, Charset cs)
    Writes a String value at the given offset, using a specific Charset
    void
    putZeroTerminatedByteArray(long offset, byte[] src, int off, int len)
     
    final void
    setMemory(long offset, long size, byte value)
    Sets the value of each byte in the memory area represented by this Pointer.
    long
    Gets the size of this memory object in bytes (optional operation).
    void
    transferFrom(long offset, Pointer other, long otherOffset, long count)
    Bulk data transfer from one memory location to another.
    void
    transferTo(long offset, Pointer other, long otherOffset, long count)
    Bulk data transfer from one memory location to another.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • IO

      static final com.kenai.jffi.MemoryIO IO
  • Constructor Details

    • DirectMemoryIO

      DirectMemoryIO(Runtime runtime, long address)
    • DirectMemoryIO

      DirectMemoryIO(Runtime runtime, int address)
  • Method Details

    • size

      public long size()
      Description copied from class: Pointer
      Gets the size of this memory object in bytes (optional operation).
      Specified by:
      size in class Pointer
      Returns:
      the size of the memory area this Pointer points to. If the size is unknown, Long.MAX_VALUE is returned}.
    • hasArray

      public boolean hasArray()
      Description copied from class: Pointer
      Indicates whether this Pointer instance is backed by an array.
      Specified by:
      hasArray in class Pointer
      Returns:
      true if, and only if, this memory object is backed by an array
    • array

      public Object array()
      Description copied from class: Pointer
      Returns the array that backs this pointer.
      Specified by:
      array in class Pointer
      Returns:
      The array that backs this pointer.
    • arrayOffset

      public int arrayOffset()
      Description copied from class: Pointer
      Returns the offset within this pointer's backing array of the first element.
      Specified by:
      arrayOffset in class Pointer
      Returns:
      The offset of the first element on the backing array
    • arrayLength

      public int arrayLength()
      Description copied from class: Pointer
      Returns the length of this pointer's backing array that is used by this pointer.
      Specified by:
      arrayLength in class Pointer
      Returns:
      The length of the backing array used
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • getByte

      public final byte getByte(long offset)
      Description copied from class: Pointer
      Reads an byte (8 bit) value at the given offset.
      Specified by:
      getByte in class Pointer
      Parameters:
      offset - The offset from the start of the memory this Pointer represents at which the value will be read.
      Returns:
      the byte value at the offset.
    • getShort

      public final short getShort(long offset)
      Description copied from class: Pointer
      Reads a short (16 bit) value at the given offset.
      Specified by:
      getShort in class Pointer
      Parameters:
      offset - The offset from the start of the memory this Pointer represents at which the value will be read.
      Returns:
      the short value at the offset.
    • getInt

      public final int getInt(long offset)
      Description copied from class: Pointer
      Reads an int (32 bit) value at the given offset.
      Specified by:
      getInt in class Pointer
      Parameters:
      offset - The offset from the start of the memory this Pointer represents at which the value will be read.
      Returns:
      the int value contained in the memory at the offset.
    • getLongLong

      public final long getLongLong(long offset)
      Description copied from class: Pointer
      Reads a long (64 bit) value at the given offset.
      Specified by:
      getLongLong in class Pointer
      Parameters:
      offset - The offset from the start of the memory this Pointer represents at which the value will be read.
      Returns:
      the long value at the offset.
    • getFloat

      public final float getFloat(long offset)
      Description copied from class: Pointer
      Reads a float (32 bit) value at the given offset.
      Specified by:
      getFloat in class Pointer
      Parameters:
      offset - The offset from the start of the memory this Pointer represents at which the value will be read.
      Returns:
      the float value at the offset.
    • getDouble

      public final double getDouble(long offset)
      Description copied from class: Pointer
      Reads a double (64 bit) value at the given offset.
      Specified by:
      getDouble in class Pointer
      Parameters:
      offset - The offset from the start of the memory this Pointer represents at which the value will be read.
      Returns:
      the double value at the offset.
    • putByte

      public final void putByte(long offset, byte value)
      Description copied from class: Pointer
      Writes a byte (8 bit) value at the given offset.
      Specified by:
      putByte in class Pointer
      Parameters:
      offset - The offset from the start of the memory this Pointer represents at which the value will be written.
      value - the byte value to be written.
    • putShort

      public final void putShort(long offset, short value)
      Description copied from class: Pointer
      Writes a short (16 bit) value at the given offset.
      Specified by:
      putShort in class Pointer
      Parameters:
      offset - The offset from the start of the memory this Pointer represents at which the value will be written.
      value - the short value to be written.
    • putInt

      public final void putInt(long offset, int value)
      Description copied from class: Pointer
      Writes an int (32 bit) value at the given offset.
      Specified by:
      putInt in class Pointer
      Parameters:
      offset - The offset from the start of the memory this Pointer represents at which the value will be written.
      value - the int value to be written.
    • putLongLong

      public final void putLongLong(long offset, long value)
      Description copied from class: Pointer
      Writes a long (64 bit) value at the given offset.
      Specified by:
      putLongLong in class Pointer
      Parameters:
      offset - The offset from the start of the memory this Pointer represents at which the value will be written.
      value - the long value to be written.
    • putFloat

      public final void putFloat(long offset, float value)
      Description copied from class: Pointer
      Writes a float (32 bit, single precision) value at the given offset.
      Specified by:
      putFloat in class Pointer
      Parameters:
      offset - The offset from the start of the memory this Pointer represents at which the value will be written.
      value - the float value to be written.
    • putDouble

      public final void putDouble(long offset, double value)
      Description copied from class: Pointer
      Writes a double (64 bit, double precision) value at the given offset.
      Specified by:
      putDouble in class Pointer
      Parameters:
      offset - The offset from the start of the memory this Pointer represents at which the value will be written.
      value - the double value to be written.
    • get

      public final void get(long offset, byte[] dst, int off, int len)
      Description copied from class: Pointer
      Bulk get method for multiple byte values. This method reads multiple byte values from consecutive addresses, beginning at the given offset, and stores them in an array.
      Specified by:
      get in class Pointer
      Parameters:
      offset - the offset from the start of the memory this Pointer represents at which the first value will be read.
      dst - the array into which values are to be stored.
      off - the start index in the dst array to begin storing the values.
      len - the number of values to be read.
    • put

      public final void put(long offset, byte[] src, int off, int len)
      Description copied from class: Pointer
      Bulk put method for multiple byte values. This method writes multiple byte values to consecutive addresses, beginning at the given offset, from an array.
      Specified by:
      put in class Pointer
      Parameters:
      offset - the offset from the start of the memory this Pointer represents at which the first value will be written.
      src - the array to get values from.
      off - the start index in the dst array to begin reading values.
      len - the number of values to be written.
    • get

      public final void get(long offset, short[] dst, int off, int len)
      Description copied from class: Pointer
      Bulk get method for multiple short values. This method reads multiple short values from consecutive addresses, beginning at the given offset, and stores them in an array.
      Specified by:
      get in class Pointer
      Parameters:
      offset - The offset from the start of the memory this Pointer represents at which the first value will be read.
      dst - The array into which values are to be stored.
      off - the start index in the dst array to begin storing the values.
      len - the number of values to be read.
    • put

      public final void put(long offset, short[] src, int off, int len)
      Description copied from class: Pointer
      Bulk put method for multiple short values. This method writes multiple short values to consecutive addresses, beginning at the given offset, from an array.
      Specified by:
      put in class Pointer
      Parameters:
      offset - the offset from the start of the memory this Pointer represents at which the first value will be written.
      src - the array to get values from.
      off - the start index in the dst array to begin reading values.
      len - the number of values to be written.
    • get

      public final void get(long offset, int[] dst, int off, int len)
      Description copied from class: Pointer
      Bulk get method for multiple int values. This method reads multiple int values from consecutive addresses, beginning at the given offset, and stores them in an array.
      Specified by:
      get in class Pointer
      Parameters:
      offset - The offset from the start of the memory this Pointer represents at which the first value will be read.
      dst - The array into which values are to be stored.
      off - the start index in the dst array to begin storing the values.
      len - the number of values to be read.
    • put

      public final void put(long offset, int[] src, int off, int len)
      Description copied from class: Pointer
      Bulk put method for multiple int values. This method writes multiple int values to consecutive addresses, beginning at the given offset, from an array.
      Specified by:
      put in class Pointer
      Parameters:
      offset - the offset from the start of the memory this Pointer represents at which the first value will be written.
      src - the array to get values from.
      off - the start index in the dst array to begin reading values.
      len - the number of values to be written.
    • get

      public final void get(long offset, long[] dst, int off, int len)
      Description copied from class: Pointer
      Bulk get method for multiple long values. This method reads multiple long values from consecutive addresses, beginning at the given offset, and stores them in an array.
      Specified by:
      get in class Pointer
      Parameters:
      offset - The offset from the start of the memory this Pointer represents at which the first value will be read.
      dst - The array into which values are to be stored.
      off - the start index in the dst array to begin storing the values.
      len - the number of values to be read.
    • put

      public final void put(long offset, long[] src, int off, int len)
      Description copied from class: Pointer
      Bulk put method for multiple long values. This method writes multiple long values to consecutive addresses, beginning at the given offset, from an array.
      Specified by:
      put in class Pointer
      Parameters:
      offset - the offset from the start of the memory this Pointer represents at which the first value will be written.
      src - the array to get values from.
      off - the start index in the dst array to begin reading values.
      len - the number of values to be written.
    • get

      public final void get(long offset, float[] dst, int off, int len)
      Description copied from class: Pointer
      Bulk get method for multiple float values. This method reads multiple float values from consecutive addresses, beginning at the given offset, and stores them in an array.
      Specified by:
      get in class Pointer
      Parameters:
      offset - The offset from the start of the memory this Pointer represents at which the first value will be read.
      dst - The array into which values are to be stored.
      off - the start index in the dst array to begin storing the values.
      len - the number of values to be read.
    • put

      public final void put(long offset, float[] src, int off, int len)
      Description copied from class: Pointer
      Bulk put method for multiple float values. This method writes multiple float values to consecutive addresses, beginning at the given offset, from an array.
      Specified by:
      put in class Pointer
      Parameters:
      offset - the offset from the start of the memory this Pointer represents at which the first value will be written.
      src - the array to get values from.
      off - the start index in the dst array to begin reading values.
      len - the number of values to be written.
    • get

      public final void get(long offset, double[] dst, int off, int len)
      Description copied from class: Pointer
      Bulk get method for multiple double values. This method reads multiple double values from consecutive addresses, beginning at the given offset, and stores them in an array.
      Specified by:
      get in class Pointer
      Parameters:
      offset - The offset from the start of the memory this Pointer represents at which the first value will be read.
      dst - The array into which values are to be stored.
      off - the start index in the dst array to begin storing the values.
      len - the number of values to be read.
    • put

      public final void put(long offset, double[] src, int off, int len)
      Description copied from class: Pointer
      Bulk put method for multiple double values. This method writes multiple double values to consecutive addresses, beginning at the given offset, from an array.
      Specified by:
      put in class Pointer
      Parameters:
      offset - the offset from the start of the memory this Pointer represents at which the first value will be written.
      src - the array to get values from.
      off - the start index in the dst array to begin reading values.
      len - the number of values to be written.
    • getPointer

      public Pointer getPointer(long offset)
      Description copied from class: Pointer
      Reads an Pointer value at the given offset.
      Specified by:
      getPointer in class Pointer
      Parameters:
      offset - the offset from the start of the memory this Pointer represents at which the value will be read.
      Returns:
      the Pointer value read from memory.
    • getPointer

      public Pointer getPointer(long offset, long size)
      Description copied from class: Pointer
      Reads an Pointer value at the given offset.
      Specified by:
      getPointer in class Pointer
      Parameters:
      offset - the offset from the start of the memory this Pointer represents at which the value will be read.
      size - the maximum size of the memory location the returned Pointer represents.
      Returns:
      the Pointer value read from memory.
    • putPointer

      public void putPointer(long offset, Pointer value)
      Description copied from class: Pointer
      Writes a Pointer value at the given offset.
      Specified by:
      putPointer in class Pointer
      Parameters:
      offset - The offset from the start of the memory this Pointer represents at which the value will be written.
      value - the Pointer value to be written to memory.
    • getString

      public String getString(long offset)
      Description copied from class: Pointer
      Reads an String value at the given offset.
      Specified by:
      getString in class Pointer
      Parameters:
      offset - the offset from the start of the memory this Pointer represents at which the value will be read.
      Returns:
      the String value read from memory.
    • getString

      public String getString(long offset, int maxLength, Charset cs)
      Description copied from class: Pointer
      Reads a String value at the given offset, using a specific Charset
      Specified by:
      getString in class Pointer
      Parameters:
      offset - the offset from the start of the memory this Pointer represents at which the value will be read.
      maxLength - the maximum size of memory to search for a NUL byte.
      cs - the Charset to use to decode the string.
      Returns:
      the String value read from memory.
    • putString

      public void putString(long offset, String string, int maxLength, Charset cs)
      Description copied from class: Pointer
      Writes a String value at the given offset, using a specific Charset
      Specified by:
      putString in class Pointer
      Parameters:
      offset - the offset from the start of the memory this Pointer represents at which the value will be written.
      string - the string to be written.
      maxLength - the maximum size of memory to use to store the string.
      cs - the Charset to use to decode the string.
    • putZeroTerminatedByteArray

      public void putZeroTerminatedByteArray(long offset, byte[] src, int off, int len)
    • indexOf

      public int indexOf(long offset, byte value, int maxlen)
      Description copied from class: Pointer
      Returns the location of a byte value within the memory area represented by this Pointer.
      Specified by:
      indexOf in class Pointer
      Parameters:
      offset - the offset from the start of the memory location this Pointer represents to begin searching.
      value - the byte value to locate.
      maxlen - the maximum number of bytes to search for the desired value.
      Returns:
      the offset from the start of the search area (i.e. relative to the offset parameter), or -1 if not found.
    • setMemory

      public final void setMemory(long offset, long size, byte value)
      Description copied from class: Pointer
      Sets the value of each byte in the memory area represented by this Pointer. to a specified value.
      Specified by:
      setMemory in class Pointer
      Parameters:
      offset - the offset from the start of the memory location this Pointer represents to begin writing to.
      size - the number of bytes to set to the value.
      value - the value to set each byte to.
    • transferTo

      public void transferTo(long offset, Pointer other, long otherOffset, long count)
      Description copied from class: Pointer
      Bulk data transfer from one memory location to another.
      Overrides:
      transferTo in class AbstractMemoryIO
      Parameters:
      offset - the offset from the start of the memory location this Pointer represents to begin copying from.
      other - the destination memory location to transfer data to.
      otherOffset - the offset from the start of the memory location the destination Pointer represents to begin copying to.
      count - the number of bytes to transfer.
    • transferFrom

      public void transferFrom(long offset, Pointer other, long otherOffset, long count)
      Description copied from class: Pointer
      Bulk data transfer from one memory location to another.
      Overrides:
      transferFrom in class AbstractMemoryIO
      Parameters:
      offset - the offset from the start of the memory location this Pointer represents to begin copying to.
      other - the destination memory location to transfer data from.
      otherOffset - the offset from the start of the memory location the destination Pointer represents to begin copying from.
      count - the number of bytes to transfer.
    • memcpy

      private static void memcpy(DirectMemoryIO src, long srcOffset, DirectMemoryIO dst, long dstOffset, long count)