Class ArrayMemoryIO

java.lang.Object
org.jruby.ext.ffi.MemoryIO
org.jruby.ext.ffi.ArrayMemoryIO

public final class ArrayMemoryIO extends MemoryIO
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    protected static class 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected static final int
     
    protected final byte[]
     
    protected static final ArrayMemoryIO.ArrayIO
     
    protected final int
     
    protected static final int
     
    protected final int
     
    protected final Ruby
     

    Fields inherited from class org.jruby.ext.ffi.MemoryIO

    address, isDirect
  • Constructor Summary

    Constructors
    Constructor
    Description
    ArrayMemoryIO(Ruby runtime, byte[] buffer, int offset, int length)
     
    ArrayMemoryIO(Ruby runtime, int size)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    final byte[]
     
    final int
     
    final int
     
    Creates a view of this memory object as a java NIO byte buffer.
    final void
     
    dup()
    Duplicates this MemoryIO, including its contents.
    final void
    get(long offset, byte[] dst, int off, int len)
    Reads an array of bytes from the memory area at the specified offset.
    final void
    get(long offset, double[] dst, int off, int len)
    Reads an array of doubles from the memory area at the specified offset.
    final void
    get(long offset, float[] dst, int off, int len)
    Reads an array of floats from the memory area at the specified offset.
    final void
    get(long offset, int[] dst, int off, int len)
    Reads an array of ints from the memory area at the specified offset.
    final void
    get(long offset, long[] dst, int off, int len)
    Reads an array of longs from the memory area at the specified offset.
    final void
    get(long offset, short[] dst, int off, int len)
    Reads an array of shorts from the memory area at the specified offset.
    final long
    getAddress(long offset)
    Reads a pointer value at the specified offset within the memory area.
    final byte
    getByte(long offset)
    Reads an 8 bit integer value from the memory area.
    final double
    getDouble(long offset)
    Reads a double value from the memory area.
    final float
    getFloat(long offset)
    Reads a float value from the memory area.
    final int
    getInt(long offset)
    Reads a 32 bit integer value from the memory area.
    final long
    getLong(long offset)
    Reads a 64 bit integer value from the memory area.
    final MemoryIO
    getMemoryIO(long offset)
    Reads a pointer value at the specified offset within the memory area, and wraps it in an abstract memory accessor.
    final long
    getNativeLong(long offset)
    Reads a native long integer value from the memory area.
    final short
    getShort(long offset)
    Reads a 16 bit integer value from the memory area.
    final byte[]
    Reads a zero terminated byte array (e.g.
    final byte[]
    getZeroTerminatedByteArray(long offset, int maxlen)
    Reads a zero terminated byte array (e.g.
    protected final int
    index(long off)
     
    final int
    indexOf(long offset, byte value)
    Gets the first index within the memory area of a particular 8 bit value.
    final int
    indexOf(long offset, byte value, int maxlen)
    Gets the first index within the memory area of a particular 8 bit value.
    final ByteOrder
    Gets the ByteOrder this MemoryIO instance will read/write values to memory in.
    final void
    put(long offset, byte[] src, int off, int len)
    Writes an array of bytes to the memory area at the specified offset.
    final void
    put(long offset, double[] src, int off, int len)
    Writes an array of doubles to the memory area at the specified offset.
    final void
    put(long offset, float[] src, int off, int len)
    Writes an array of floats to the memory area at the specified offset.
    final void
    put(long offset, int[] src, int off, int len)
    Writes an array of ints to the memory area at the specified offset.
    final void
    put(long offset, long[] src, int off, int len)
    Writes an array of longs to the memory area at the specified offset.
    final void
    put(long offset, short[] src, int off, int len)
    Writes an array of shorts to the memory area at the specified offset.
    final void
    putAddress(long offset, long value)
    Writes a pointer value to the memory area at the specified offset.
    final void
    putByte(long offset, byte value)
    Writes an 8 bit integer value to the memory area at the specified offset.
    final void
    putDouble(long offset, double value)
    Writes a 64 bit float value to the memory area at the specified offset.
    final void
    putFloat(long offset, float value)
    Writes a 32 bit float value to the memory area at the specified offset.
    final void
    putInt(long offset, int value)
    Writes a 32 bit integer value to the memory area at the specified offset.
    final void
    putLong(long offset, long value)
    Writes a 64 bit integer value to the memory area at the specified offset.
    final void
    putMemoryIO(long offset, MemoryIO value)
    Writes a pointer value to the memory area at the specified offset.
    final void
    putNativeLong(long offset, long value)
    Writes a native long integer value to the memory area at the specified offset.
    final void
    putShort(long offset, short value)
    Writes a 16 bit integer value to the memory area at the specified offset.
    void
    putZeroTerminatedByteArray(long offset, byte[] bytes, int off, int len)
    Writes a byte array to memory, and appends a zero terminator
    final void
    setMemory(long offset, long size, byte value)
    Sets the contents of the memory area to the value.
    slice(long offset)
    Creates a new MemoryIO pointing to a subset of the memory area of this MemoryIO.
    slice(long offset, long size)
    Creates a new MemoryIO pointing to a subset of the memory area of this MemoryIO.

    Methods inherited from class org.jruby.ext.ffi.MemoryIO

    address, isDirect, isNull

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • IO

      protected static final ArrayMemoryIO.ArrayIO IO
    • LONG_SIZE

      protected static final int LONG_SIZE
    • ADDRESS_SIZE

      protected static final int ADDRESS_SIZE
    • runtime

      protected final Ruby runtime
    • buffer

      protected final byte[] buffer
    • offset

      protected final int offset
    • length

      protected final int length
  • Constructor Details

    • ArrayMemoryIO

      public ArrayMemoryIO(Ruby runtime, byte[] buffer, int offset, int length)
    • ArrayMemoryIO

      public ArrayMemoryIO(Ruby runtime, int size)
  • Method Details

    • array

      public final byte[] array()
      Specified by:
      array in class MemoryIO
    • arrayOffset

      public final int arrayOffset()
      Specified by:
      arrayOffset in class MemoryIO
    • arrayLength

      public final int arrayLength()
      Specified by:
      arrayLength in class MemoryIO
    • index

      protected final int index(long off)
    • order

      public final ByteOrder order()
      Description copied from class: MemoryIO
      Gets the ByteOrder this MemoryIO instance will read/write values to memory in.
      Specified by:
      order in class MemoryIO
      Returns:
      The current ByteOrder
    • slice

      public ArrayMemoryIO slice(long offset)
      Description copied from class: MemoryIO
      Creates a new MemoryIO pointing to a subset of the memory area of this MemoryIO.
      Specified by:
      slice in class MemoryIO
      Parameters:
      offset - The offset within the existing memory area to start the new MemoryIO at.
      Returns:
      A MemoryIO instance.
    • slice

      public ArrayMemoryIO slice(long offset, long size)
      Description copied from class: MemoryIO
      Creates a new MemoryIO pointing to a subset of the memory area of this MemoryIO.
      Specified by:
      slice in class MemoryIO
      Parameters:
      offset - The offset within the existing memory area to start the new MemoryIO at.
      size - The size of the new slice.
      Returns:
      A MemoryIO instance.
    • dup

      public ArrayMemoryIO dup()
      Description copied from class: MemoryIO
      Duplicates this MemoryIO, including its contents.
      Specified by:
      dup in class MemoryIO
      Returns:
      A MemoryIO instance.
    • asByteBuffer

      public ByteBuffer asByteBuffer()
      Description copied from class: MemoryIO
      Creates a view of this memory object as a java NIO byte buffer.
      Specified by:
      asByteBuffer in class MemoryIO
      Returns:
      A ByteBuffer instance
    • getMemoryIO

      public final MemoryIO getMemoryIO(long offset)
      Description copied from class: MemoryIO
      Reads a pointer value at the specified offset within the memory area, and wraps it in an abstract memory accessor.
      Specified by:
      getMemoryIO in class MemoryIO
      Parameters:
      offset - The offset within the memory area to read the value.
      Returns:
      A DirectMemoryIO accessor that can be used to access the memory pointed to by the address.
    • putMemoryIO

      public final void putMemoryIO(long offset, MemoryIO value)
      Description copied from class: MemoryIO
      Writes a pointer value to the memory area at the specified offset.
      Specified by:
      putMemoryIO in class MemoryIO
      Parameters:
      offset - The offset within the memory area to write the value.
      value - The pointer value to write to the memory location.
    • getByte

      public final byte getByte(long offset)
      Description copied from class: MemoryIO
      Reads an 8 bit integer value from the memory area.
      Specified by:
      getByte in class MemoryIO
      Parameters:
      offset - The offset within the memory area to read the value.
      Returns:
      The 8 bit integer value read from offset
    • getShort

      public final short getShort(long offset)
      Description copied from class: MemoryIO
      Reads a 16 bit integer value from the memory area.
      Specified by:
      getShort in class MemoryIO
      Parameters:
      offset - The offset within the memory area to read the value.
      Returns:
      The 16 bit integer value read from offset
    • getInt

      public final int getInt(long offset)
      Description copied from class: MemoryIO
      Reads a 32 bit integer value from the memory area.
      Specified by:
      getInt in class MemoryIO
      Parameters:
      offset - The offset within the memory area to read the value.
      Returns:
      The 32 bit integer value read from offset
    • getLong

      public final long getLong(long offset)
      Description copied from class: MemoryIO
      Reads a 64 bit integer value from the memory area.
      Specified by:
      getLong in class MemoryIO
      Parameters:
      offset - The offset within the memory area to read the value.
      Returns:
      The 64 bit integer value read from offset
    • getNativeLong

      public final long getNativeLong(long offset)
      Description copied from class: MemoryIO
      Reads a native long integer value from the memory area.

      A native long is 32bits on either ILP32 or LLP64 architectures, and 64 bits on an LP64 architecture.

      This means that it will always read a 32bit value on Windows, but on Unix systems such as MacOS or Linux, it will read a 32bit value on 32bit systems, and a 64bit value on 64bit systems.

      Specified by:
      getNativeLong in class MemoryIO
      Parameters:
      offset - The offset within the memory area to read the value.
      Returns:
      The native long value read from offset
    • getFloat

      public final float getFloat(long offset)
      Description copied from class: MemoryIO
      Reads a float value from the memory area.
      Specified by:
      getFloat in class MemoryIO
      Parameters:
      offset - The offset within the memory area to read the value.
      Returns:
      The float value read from offset
    • getDouble

      public final double getDouble(long offset)
      Description copied from class: MemoryIO
      Reads a double value from the memory area.
      Specified by:
      getDouble in class MemoryIO
      Parameters:
      offset - The offset within the memory area to read the value.
      Returns:
      The double value read from offset
    • getAddress

      public final long getAddress(long offset)
      Description copied from class: MemoryIO
      Reads a pointer value at the specified offset within the memory area.
      Specified by:
      getAddress in class MemoryIO
      Parameters:
      offset - The offset within the memory area to read the value.
      Returns:
      A long value that represents the address.
    • putByte

      public final void putByte(long offset, byte value)
      Description copied from class: MemoryIO
      Writes an 8 bit integer value to the memory area at the specified offset.
      Specified by:
      putByte in class MemoryIO
      Parameters:
      offset - The offset within the memory area to write the value.
      value - The 8 bit integer value to write to the memory location.
    • putShort

      public final void putShort(long offset, short value)
      Description copied from class: MemoryIO
      Writes a 16 bit integer value to the memory area at the specified offset.
      Specified by:
      putShort in class MemoryIO
      Parameters:
      offset - The offset within the memory area to write the value.
      value - The 16 bit integer value to write to the memory location.
    • putInt

      public final void putInt(long offset, int value)
      Description copied from class: MemoryIO
      Writes a 32 bit integer value to the memory area at the specified offset.
      Specified by:
      putInt in class MemoryIO
      Parameters:
      offset - The offset within the memory area to write the value.
      value - The 32 bit integer value to write to the memory location.
    • putLong

      public final void putLong(long offset, long value)
      Description copied from class: MemoryIO
      Writes a 64 bit integer value to the memory area at the specified offset.
      Specified by:
      putLong in class MemoryIO
      Parameters:
      offset - The offset within the memory area to write the value.
      value - The 64 bit integer value to write to the memory location.
    • putNativeLong

      public final void putNativeLong(long offset, long value)
      Description copied from class: MemoryIO
      Writes a native long integer value to the memory area at the specified offset.
      Specified by:
      putNativeLong in class MemoryIO
      Parameters:
      offset - The offset within the memory area to write the value.
      value - The native long integer value to write to the memory location.
    • putFloat

      public final void putFloat(long offset, float value)
      Description copied from class: MemoryIO
      Writes a 32 bit float value to the memory area at the specified offset.
      Specified by:
      putFloat in class MemoryIO
      Parameters:
      offset - The offset within the memory area to write the value.
      value - The 32 bit float value to write to the memory location.
    • putDouble

      public final void putDouble(long offset, double value)
      Description copied from class: MemoryIO
      Writes a 64 bit float value to the memory area at the specified offset.
      Specified by:
      putDouble in class MemoryIO
      Parameters:
      offset - The offset within the memory area to write the value.
      value - The 64 bit float value to write to the memory location.
    • putAddress

      public final void putAddress(long offset, long value)
      Description copied from class: MemoryIO
      Writes a pointer value to the memory area at the specified offset.
      Specified by:
      putAddress in class MemoryIO
      Parameters:
      offset - The offset within the memory area to write the value.
      value - The pointer value to write to the memory location.
    • get

      public final void get(long offset, byte[] dst, int off, int len)
      Description copied from class: MemoryIO
      Reads an array of bytes from the memory area at the specified offset.
      Specified by:
      get in class MemoryIO
      Parameters:
      offset - The offset within the memory area to read the bytes.
      dst - The output byte array to place the data.
      off - The offset within the byte array to start copying.
      len - The length of data to read.
    • put

      public final void put(long offset, byte[] src, int off, int len)
      Description copied from class: MemoryIO
      Writes an array of bytes to the memory area at the specified offset.
      Specified by:
      put in class MemoryIO
      Parameters:
      offset - The offset within the memory area to start writing the bytes.
      src - The byte array to write to the memory area.
      off - The offset within the byte array to start copying.
      len - The length of data to write.
    • get

      public final void get(long offset, short[] dst, int off, int len)
      Description copied from class: MemoryIO
      Reads an array of shorts from the memory area at the specified offset.
      Specified by:
      get in class MemoryIO
      Parameters:
      offset - The offset within the memory area to read the shorts.
      dst - The output array to place the data in.
      off - The offset within the array to start copying.
      len - The number of shorts to read.
    • put

      public final void put(long offset, short[] src, int off, int len)
      Description copied from class: MemoryIO
      Writes an array of shorts to the memory area at the specified offset.
      Specified by:
      put in class MemoryIO
      Parameters:
      offset - The offset within the memory area to start writing the shorts.
      src - The array to write to the memory area.
      off - The offset within the array to start copying.
      len - The number of shorts to write.
    • get

      public final void get(long offset, int[] dst, int off, int len)
      Description copied from class: MemoryIO
      Reads an array of ints from the memory area at the specified offset.
      Specified by:
      get in class MemoryIO
      Parameters:
      offset - The offset within the memory area to read the ints.
      dst - The output array to place the data in.
      off - The offset within the array to start copying.
      len - The number of ints to read.
    • put

      public final void put(long offset, int[] src, int off, int len)
      Description copied from class: MemoryIO
      Writes an array of ints to the memory area at the specified offset.
      Specified by:
      put in class MemoryIO
      Parameters:
      offset - The offset within the memory area to start writing the ints.
      src - The array to write to the memory area.
      off - The offset within the array to start copying.
      len - The number of ints to write.
    • get

      public final void get(long offset, long[] dst, int off, int len)
      Description copied from class: MemoryIO
      Reads an array of longs from the memory area at the specified offset.
      Specified by:
      get in class MemoryIO
      Parameters:
      offset - The offset within the memory area to read the longs.
      dst - The output array to place the data in.
      off - The offset within the array to start copying.
      len - The number of longs to read.
    • put

      public final void put(long offset, long[] src, int off, int len)
      Description copied from class: MemoryIO
      Writes an array of longs to the memory area at the specified offset.
      Specified by:
      put in class MemoryIO
      Parameters:
      offset - The offset within the memory area to start writing the longs.
      src - The array to write to the memory area.
      off - The offset within the array to start copying.
      len - The number of longs to write.
    • get

      public final void get(long offset, float[] dst, int off, int len)
      Description copied from class: MemoryIO
      Reads an array of floats from the memory area at the specified offset.
      Specified by:
      get in class MemoryIO
      Parameters:
      offset - The offset within the memory area to read the floats.
      dst - The output array to place the data in.
      off - The offset within the array to start copying.
      len - The number of floats to read.
    • put

      public final void put(long offset, float[] src, int off, int len)
      Description copied from class: MemoryIO
      Writes an array of floats to the memory area at the specified offset.
      Specified by:
      put in class MemoryIO
      Parameters:
      offset - The offset within the memory area to start writing the floats.
      src - The array to write to the memory area.
      off - The offset within the array to start copying.
      len - The number of floats to write.
    • get

      public final void get(long offset, double[] dst, int off, int len)
      Description copied from class: MemoryIO
      Reads an array of doubles from the memory area at the specified offset.
      Specified by:
      get in class MemoryIO
      Parameters:
      offset - The offset within the memory area to read the doubles.
      dst - The output array to place the data in.
      off - The offset within the array to start copying.
      len - The number of doubles to read.
    • put

      public final void put(long offset, double[] src, int off, int len)
      Description copied from class: MemoryIO
      Writes an array of doubles to the memory area at the specified offset.
      Specified by:
      put in class MemoryIO
      Parameters:
      offset - The offset within the memory area to start writing the doubles.
      src - The array to write to the memory area.
      off - The offset within the array to start copying.
      len - The number of doubles to write.
    • indexOf

      public final int indexOf(long offset, byte value)
      Description copied from class: MemoryIO
      Gets the first index within the memory area of a particular 8 bit value.
      Specified by:
      indexOf in class MemoryIO
      Parameters:
      offset - The offset within the memory area to start searching.
      value - The value to search for.
      Returns:
      The index of the value, relative to offset.
    • indexOf

      public final int indexOf(long offset, byte value, int maxlen)
      Description copied from class: MemoryIO
      Gets the first index within the memory area of a particular 8 bit value.
      Specified by:
      indexOf in class MemoryIO
      Parameters:
      offset - The offset within the memory area to start searching.
      value - The value to search for.
      Returns:
      The index of the value, relative to offset.
    • setMemory

      public final void setMemory(long offset, long size, byte value)
      Description copied from class: MemoryIO
      Sets the contents of the memory area to the value.
      Specified by:
      setMemory in class MemoryIO
      Parameters:
      offset - The offset within the memory area to start writing.
      size - The number of bytes to set to the value.
      value - The value to set each byte to.
    • getZeroTerminatedByteArray

      public final byte[] getZeroTerminatedByteArray(long offset)
      Description copied from class: MemoryIO
      Reads a zero terminated byte array (e.g. an ascii or utf-8 string)
      Specified by:
      getZeroTerminatedByteArray in class MemoryIO
      Parameters:
      offset - The offset within the memory area of the start of the string.
      Returns:
      A byte array containing a copy of the data.
    • getZeroTerminatedByteArray

      public final byte[] getZeroTerminatedByteArray(long offset, int maxlen)
      Description copied from class: MemoryIO
      Reads a zero terminated byte array (e.g. an ascii or utf-8 string)
      Specified by:
      getZeroTerminatedByteArray in class MemoryIO
      Parameters:
      offset - The offset within the memory area of the start of the string.
      maxlen - The maximum length to search for the zero byte terminator.
      Returns:
      A byte array containing a copy of the data.
    • putZeroTerminatedByteArray

      public void putZeroTerminatedByteArray(long offset, byte[] bytes, int off, int len)
      Description copied from class: MemoryIO
      Writes a byte array to memory, and appends a zero terminator
      Specified by:
      putZeroTerminatedByteArray in class MemoryIO
      Parameters:
      offset - The offset within the memory area of the start of the string.
      bytes - The byte array to write to the memory.
      off - The offset with the byte array to start copying.
      len - The number of bytes of the byte array to write to the memory area. (not including zero byte)
    • clear

      public final void clear()