Interface MemoryAccessor


@Inclubating
public interface MemoryAccessor
Abstraction over an address space of readable and writable bytes, also can used to allocate/reallocate/deallocate buffer's.

Author:
Ardika Rommy Sanjaya
  • Method Summary

    Modifier and Type Method Description
    long allocate​(int size)
    Allocate memory buffer's with given size.
    void deallocate​(long addr)
    Release/freeing block of memory.
    byte getByte​(long addr)
    Reads the byte value from given address.
    void getBytes​(long srcAddr, int index, byte[] dst, int dstIndex, int size)
    Copies memory from given source address and source index to a Java byte array.
    void getBytes​(long srcAddr, int index, long dstAddr, int dstIndex, int size)
    Copies memory from given source address and source index to given destination address as given destination index and size.
    int getInt​(long addr)
    Reads the int value from given address.
    int getIntLE​(long addr)
    Reads the little endian int value from given address.
    long getLong​(long addr)
    Reads the long value from given address.
    long getLongLE​(long addr)
    Reads the little endian long value from given address.
    short getShort​(long addr)
    Reads the short value from given address.
    short getShortLE​(long addr)
    Reads the little endian short value from given address.
    ByteBuffer nioBuffer​(long addr, int size)
    Wrap low-lavel memory into direct ByteBuffer with no cleaner.
    long reallocate​(long addr, int size)
    If the dynamically allocated memory is insufficient or more than required, you can change the size of previously allocated memory using this funtions.
    void setByte​(long addr, int val)
    Writes the given byte value to given address.
    void setBytes​(long dstAddr, int index, byte[] src, int srcIndex, int size)
    Copies bytes from a Java byte array into this accessor's address space.
    void setBytes​(long dstAddr, int index, long srcAddr, int srcIndex, int size)
    Copies memory from given source address and source index to given destination address as given destination index and size.
    void setInt​(long addr, int val)
    Writes the given int value to given address.
    void setIntLE​(long addr, int val)
    Writes the given little endian int value to given address.
    void setLong​(long addr, long val)
    Writes the given long value to given address.
    void setLongLE​(long addr, long val)
    Writes the given little endian long value to given address.
    void setShort​(long addr, int val)
    Writes the given short value to given address.
    void setShortLE​(long addr, int val)
    Writes the given little endian short value to given address.
  • Method Details

    • allocate

      long allocate​(int size)
      Allocate memory buffer's with given size.
      Parameters:
      size - size of buffer (in bytes).
      Returns:
      returns memory address of begining bytes.
    • reallocate

      long reallocate​(long addr, int size)
      If the dynamically allocated memory is insufficient or more than required, you can change the size of previously allocated memory using this funtions.
      Parameters:
      addr - memory address.
      size - new size of buffer (in bytes).
      Returns:
      returns memory current address.
    • deallocate

      void deallocate​(long addr)
      Release/freeing block of memory.
      Parameters:
      addr - memory address.
    • nioBuffer

      ByteBuffer nioBuffer​(long addr, int size)
      Wrap low-lavel memory into direct ByteBuffer with no cleaner.
      Parameters:
      addr - memory address.
      size - size of memory block.
      Returns:
      returns direct ByteBuffer with no cleaner.
    • getByte

      byte getByte​(long addr)
      Reads the byte value from given address.
      Parameters:
      addr - the address where the byte value will be read from.
      Returns:
      the byte value that was read.
    • getShort

      short getShort​(long addr)
      Reads the short value from given address.
      Parameters:
      addr - the address where the short value will be read from.
      Returns:
      the short value that was read.
    • getShortLE

      short getShortLE​(long addr)
      Reads the little endian short value from given address.
      Parameters:
      addr - the address where the short value will be read from.
      Returns:
      the little endian short value that was read.
    • getInt

      int getInt​(long addr)
      Reads the int value from given address.
      Parameters:
      addr - the address where the int value will be read from.
      Returns:
      the int value that was read.
    • getIntLE

      int getIntLE​(long addr)
      Reads the little endian int value from given address.
      Parameters:
      addr - the address where the int value will be read from.
      Returns:
      the little indian int value that was read.
    • getLong

      long getLong​(long addr)
      Reads the long value from given address.
      Parameters:
      addr - the address where the long value will be read from.
      Returns:
      the long value that was read.
    • getLongLE

      long getLongLE​(long addr)
      Reads the little endian long value from given address.
      Parameters:
      addr - the address where the long value will be read from.
      Returns:
      the little endian long value that was read.
    • getBytes

      void getBytes​(long srcAddr, int index, long dstAddr, int dstIndex, int size)
      Copies memory from given source address and source index to given destination address as given destination index and size.
      Parameters:
      srcAddr - the source address to be copied from.
      index - the source address (specified offset).
      dstAddr - the destination address to be copied to.
      dstIndex - the destination address (specified offset) to be copied to.
      size - the number of bytes to be copied.
    • getBytes

      void getBytes​(long srcAddr, int index, byte[] dst, int dstIndex, int size)
      Copies memory from given source address and source index to a Java byte array.
      Parameters:
      srcAddr - the source address to be copied from.
      index - the source address (specified offset).
      dst - the destination byte array.
      dstIndex - the destination byte array offset to be copied.
      size - number of bytes to copy.
    • setByte

      void setByte​(long addr, int val)
      Writes the given byte value to given address.
      Parameters:
      addr - the address where the byte value will be written to.
      val - the byte value to be written.
    • setShort

      void setShort​(long addr, int val)
      Writes the given short value to given address.
      Parameters:
      addr - the address where the short value will be written to.
      val - the short value to be written.
    • setShortLE

      void setShortLE​(long addr, int val)
      Writes the given little endian short value to given address.
      Parameters:
      addr - the address where the little endian short value will be written to.
      val - the little endian short value to be written.
    • setInt

      void setInt​(long addr, int val)
      Writes the given int value to given address.
      Parameters:
      addr - the address where the int value will be written to.
      val - the int value to be written.
    • setIntLE

      void setIntLE​(long addr, int val)
      Writes the given little endian int value to given address.
      Parameters:
      addr - the address where the little endian int value will be written to.
      val - the little endian int value to be written.
    • setLong

      void setLong​(long addr, long val)
      Writes the given long value to given address.
      Parameters:
      addr - the address where the long value will be written to.
      val - the long value to be written.
    • setLongLE

      void setLongLE​(long addr, long val)
      Writes the given little endian long value to given address.
      Parameters:
      addr - the address where the little endian long value will be written to.
      val - the little endian long value to be written.
    • setBytes

      void setBytes​(long dstAddr, int index, long srcAddr, int srcIndex, int size)
      Copies memory from given source address and source index to given destination address as given destination index and size.
      Parameters:
      dstAddr - the destination address to be copied to.
      index - the destination address (specified offset) to be copied to.
      srcAddr - the source address to be copied from.
      srcIndex - the source address (specified offset).
      size - the number of bytes to be copied.
    • setBytes

      void setBytes​(long dstAddr, int index, byte[] src, int srcIndex, int size)
      Copies bytes from a Java byte array into this accessor's address space.
      Parameters:
      dstAddr - address where the first byte will be written.
      index - the destination address (specified offset) to be copied to.
      src - source byte array.
      srcIndex - the offset of source byte array.
      size - the number of bytes to be copied.