Class MallocBytez

java.lang.Object
org.nustaq.offheap.bytez.malloc.MallocBytez
All Implemented Interfaces:
BasicBytez, ByteSink, ByteSource, Bytez

public class MallocBytez
extends java.lang.Object
implements Bytez
Date: 17.11.13 Time: 00:01 implementation of Bytez interface using unsafe on raw allocated memory
  • Field Summary

    Fields 
    Modifier and Type Field Description
    protected long baseAdress  
    protected long length  
  • Constructor Summary

    Constructors 
    Constructor Description
    MallocBytez​(long adr, long len)  
  • Method Summary

    Modifier and Type Method Description
    byte[] asByteArray()  
    void clear()  
    boolean compareAndSwapInt​(long offset, int expect, int newVal)  
    boolean compareAndSwapLong​(long offset, long expect, long newVal)  
    void copyTo​(BasicBytez other, long otherByteIndex, long myByteIndex, long lenBytes)  
    boolean equals​(java.lang.Object obj)  
    byte get​(long byteIndex)  
    void getArr​(long byteIndex, byte[] target, int elemoff, int numElems)
    copy to a byte array
    int getBALength()  
    int getBAOffsetIndex()  
    long getBaseAdress()  
    boolean getBool​(long byteIndex)  
    void getBooleanArr​(long byteIndex, boolean[] target, int elemoff, int numElems)
    see getArr
    char getChar​(long byteIndex)  
    void getCharArr​(long byteIndex, char[] target, int elemoff, int numElems)
    see getArr
    double getDouble​(long byteIndex)  
    void getDoubleArr​(long byteIndex, double[] target, int elemoff, int numElems)
    see getArr
    float getFloat​(long byteIndex)  
    void getFloatArr​(long byteIndex, float[] target, int elemoff, int numElems)
    see getArr
    int getInt​(long byteIndex)  
    void getIntArr​(long byteIndex, int[] target, int elemoff, int numElems)
    see getArr
    long getLength()  
    long getLong​(long byteIndex)  
    void getLongArr​(long byteIndex, long[] target, int elemoff, int numElems)
    see getArr
    short getShort​(long byteIndex)  
    void getShortArr​(long byteIndex, short[] target, int elemoff, int numElems)
    see getArr
    int hashCode()  
    long length()  
    BasicBytez newInstance​(long size)  
    void put​(long byteIndex, byte value)  
    void putBool​(long byteIndex, boolean val)  
    void putChar​(long byteIndex, char c)  
    void putDouble​(long byteIndex, double d)  
    void putFloat​(long byteIndex, float f)  
    void putInt​(long byteIndex, int i)  
    void putLong​(long byteIndex, long l)  
    void putShort​(long byteIndex, short s)  
    void set​(long byteIndex, byte[] source, int elemoff, int numElems)  
    void setBase​(long adr, long len)  
    void setBoolean​(long byteIndex, boolean[] o, int elemoff, int numElems)  
    void setChar​(long byteIndex, char[] source, int elemoff, int numElems)  
    void setDouble​(long byteIndex, double[] source, int elemoff, int numElems)  
    void setFloat​(long byteIndex, float[] source, int elemoff, int numElems)  
    void setInt​(long byteIndex, int[] source, int elemoff, int numElems)  
    void setLong​(long byteIndex, long[] source, int elemoff, int numElems)  
    void setShort​(long byteIndex, short[] source, int elemoff, int numElems)  
    MallocBytez slice​(long off, int len)  
    byte[] toBytes​(long startIndex, int len)  

    Methods inherited from class java.lang.Object

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

  • Constructor Details

    • MallocBytez

      public MallocBytez​(long adr, long len)
  • Method Details

    • setBase

      public void setBase​(long adr, long len)
    • slice

      public MallocBytez slice​(long off, int len)
      Specified by:
      slice in interface Bytez
    • get

      public byte get​(long byteIndex)
      Specified by:
      get in interface BasicBytez
      Specified by:
      get in interface ByteSource
    • getBool

      public boolean getBool​(long byteIndex)
      Specified by:
      getBool in interface BasicBytez
    • getChar

      public char getChar​(long byteIndex)
      Specified by:
      getChar in interface BasicBytez
    • getShort

      public short getShort​(long byteIndex)
      Specified by:
      getShort in interface BasicBytez
    • getInt

      public int getInt​(long byteIndex)
      Specified by:
      getInt in interface BasicBytez
    • getLong

      public long getLong​(long byteIndex)
      Specified by:
      getLong in interface BasicBytez
    • getFloat

      public float getFloat​(long byteIndex)
      Specified by:
      getFloat in interface BasicBytez
    • getDouble

      public double getDouble​(long byteIndex)
      Specified by:
      getDouble in interface BasicBytez
    • put

      public void put​(long byteIndex, byte value)
      Specified by:
      put in interface BasicBytez
      Specified by:
      put in interface ByteSink
    • putBool

      public void putBool​(long byteIndex, boolean val)
      Specified by:
      putBool in interface BasicBytez
    • putChar

      public void putChar​(long byteIndex, char c)
      Specified by:
      putChar in interface BasicBytez
    • putShort

      public void putShort​(long byteIndex, short s)
      Specified by:
      putShort in interface BasicBytez
    • putInt

      public void putInt​(long byteIndex, int i)
      Specified by:
      putInt in interface BasicBytez
    • putLong

      public void putLong​(long byteIndex, long l)
      Specified by:
      putLong in interface BasicBytez
    • putFloat

      public void putFloat​(long byteIndex, float f)
      Specified by:
      putFloat in interface BasicBytez
    • putDouble

      public void putDouble​(long byteIndex, double d)
      Specified by:
      putDouble in interface BasicBytez
    • length

      public long length()
      Specified by:
      length in interface BasicBytez
      Specified by:
      length in interface ByteSink
      Specified by:
      length in interface ByteSource
    • getArr

      public void getArr​(long byteIndex, byte[] target, int elemoff, int numElems)
      Description copied from interface: BasicBytez
      copy to a byte array
      Specified by:
      getArr in interface BasicBytez
      Parameters:
      byteIndex - - offset index in this buffer to start copying
      target - - array to copy to
      elemoff - - offset in target array
      numElems - - length to copy to
    • getCharArr

      public void getCharArr​(long byteIndex, char[] target, int elemoff, int numElems)
      Description copied from interface: BasicBytez
      see getArr
      Specified by:
      getCharArr in interface BasicBytez
    • getShortArr

      public void getShortArr​(long byteIndex, short[] target, int elemoff, int numElems)
      Description copied from interface: BasicBytez
      see getArr
      Specified by:
      getShortArr in interface BasicBytez
    • getIntArr

      public void getIntArr​(long byteIndex, int[] target, int elemoff, int numElems)
      Description copied from interface: BasicBytez
      see getArr
      Specified by:
      getIntArr in interface BasicBytez
    • getLongArr

      public void getLongArr​(long byteIndex, long[] target, int elemoff, int numElems)
      Description copied from interface: BasicBytez
      see getArr
      Specified by:
      getLongArr in interface BasicBytez
    • getFloatArr

      public void getFloatArr​(long byteIndex, float[] target, int elemoff, int numElems)
      Description copied from interface: BasicBytez
      see getArr
      Specified by:
      getFloatArr in interface BasicBytez
    • getDoubleArr

      public void getDoubleArr​(long byteIndex, double[] target, int elemoff, int numElems)
      Description copied from interface: BasicBytez
      see getArr
      Specified by:
      getDoubleArr in interface BasicBytez
    • getBooleanArr

      public void getBooleanArr​(long byteIndex, boolean[] target, int elemoff, int numElems)
      Description copied from interface: BasicBytez
      see getArr
      Specified by:
      getBooleanArr in interface BasicBytez
    • set

      public void set​(long byteIndex, byte[] source, int elemoff, int numElems)
      Specified by:
      set in interface BasicBytez
    • setChar

      public void setChar​(long byteIndex, char[] source, int elemoff, int numElems)
      Specified by:
      setChar in interface BasicBytez
    • setShort

      public void setShort​(long byteIndex, short[] source, int elemoff, int numElems)
      Specified by:
      setShort in interface BasicBytez
    • setInt

      public void setInt​(long byteIndex, int[] source, int elemoff, int numElems)
      Specified by:
      setInt in interface BasicBytez
    • setLong

      public void setLong​(long byteIndex, long[] source, int elemoff, int numElems)
      Specified by:
      setLong in interface BasicBytez
    • setFloat

      public void setFloat​(long byteIndex, float[] source, int elemoff, int numElems)
      Specified by:
      setFloat in interface BasicBytez
    • setDouble

      public void setDouble​(long byteIndex, double[] source, int elemoff, int numElems)
      Specified by:
      setDouble in interface BasicBytez
    • setBoolean

      public void setBoolean​(long byteIndex, boolean[] o, int elemoff, int numElems)
      Specified by:
      setBoolean in interface BasicBytez
    • copyTo

      public void copyTo​(BasicBytez other, long otherByteIndex, long myByteIndex, long lenBytes)
      Specified by:
      copyTo in interface BasicBytez
      Specified by:
      copyTo in interface ByteSink
    • newInstance

      public BasicBytez newInstance​(long size)
      Specified by:
      newInstance in interface BasicBytez
    • compareAndSwapInt

      public boolean compareAndSwapInt​(long offset, int expect, int newVal)
      Specified by:
      compareAndSwapInt in interface Bytez
    • compareAndSwapLong

      public boolean compareAndSwapLong​(long offset, long expect, long newVal)
      Specified by:
      compareAndSwapLong in interface Bytez
    • toBytes

      public byte[] toBytes​(long startIndex, int len)
      Specified by:
      toBytes in interface Bytez
    • asByteArray

      public byte[] asByteArray()
      Specified by:
      asByteArray in interface Bytez
      Returns:
      return the underlying byte array, not supported by MallocBytez !. Use getArr to extract data by copy instead.
    • getBAOffsetIndex

      public int getBAOffsetIndex()
      Specified by:
      getBAOffsetIndex in interface Bytez
      Returns:
      the start index inside the byte array returned by asByteArray, not supported by MallocBytez
    • getBALength

      public int getBALength()
      Specified by:
      getBALength in interface Bytez
      Returns:
      the length inside the byte array returned by asByteArray, not supported by MallocBytez
    • hashCode

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

      public boolean equals​(java.lang.Object obj)
      Overrides:
      equals in class java.lang.Object
    • getBaseAdress

      public long getBaseAdress()
    • getLength

      public long getLength()
    • clear

      public void clear()