Tabnine Logo
GridUnsafeMemory
Code IndexAdd Tabnine to your IDE (free)

How to use
GridUnsafeMemory
in
org.apache.ignite.internal.util.offheap.unsafe

Best Java code snippets using org.apache.ignite.internal.util.offheap.unsafe.GridUnsafeMemory (Showing top 20 results out of 315)

origin: apache/ignite

/**
 * Stores value to the specified memory location. If specified pointer is {@code 0}, then will
 * allocate required space. If size of allocated space is not enough to hold given values, will
 * reallocate memory.
 *
 * @param ptr Optional pointer to allocated memory. First 4 bytes in allocated region must contain
 *      size of allocated chunk.
 * @param val Value to store.
 * @param type Value type.
 * @return Pointer.
 */
public long putOffHeap(long ptr, byte[] val, byte type) {
  int size = val.length;
  assert size != 0;
  int allocated = ptr == 0 ? 0 : readInt(ptr);
  if (allocated != size) {
    if (ptr != 0)
      release(ptr, allocated + 5);
    ptr = allocate(size + 5);
    writeInt(ptr, size);
  }
  writeByte(ptr + 4, type);
  writeBytes(ptr + 5, val);
  return ptr;
}
origin: apache/ignite

/**
 * Get value stored in offheap along with a value type.
 *
 * @param ptr Pointer to read.
 * @return Stored byte array and "raw bytes" flag.
 */
public IgniteBiTuple<byte[], Byte> get(long ptr) {
  assert ptr != 0;
  int size = readInt(ptr);
  byte type = readByte(ptr + 4);
  byte[] bytes = readBytes(ptr + 5, size);
  return new IgniteBiTuple<>(bytes, type);
}
origin: apache/ignite

/** {@inheritDoc} */
@Override public long allocatedSize() {
  return mem.allocatedSize();
}
origin: apache/ignite

/**
 * Releases off-heap memory allocated by {@link #putOffHeap} method.
 *
 * @param ptr Optional pointer returned by {@link #putOffHeap}.
 */
public void removeOffHeap(long ptr) {
  if (ptr != 0)
    release(ptr, readInt(ptr) + 5);
}
origin: apache/ignite

/**
 * @throws Exception If failed.
 */
@Test
public void testLong() throws Exception {
  GridUnsafeMemory mem = new GridUnsafeMemory(64);
  int size = 32;
  long addr = mem.allocate(size);
  try {
    long l1 = 123456;
    mem.writeLong(addr, l1);
    long l2 = mem.readLong(addr);
    assertEquals(l1, l2);
    long l3 = 654321;
    mem.writeLongVolatile(addr, l3);
    long l4 = 666666;
    assertTrue(mem.casLong(addr, l3, l4));
    assertFalse(mem.casLong(addr, l3, 0));
    assertEquals(l4, mem.readLongVolatile(addr));
  }
  finally {
    mem.release(addr, size);
  }
}
origin: apache/ignite

/**
 * @throws Exception If failed.
 */
@Test
public void testByte() throws Exception {
  GridUnsafeMemory mem = new GridUnsafeMemory(64);
  int size = 32;
  long addr = mem.allocate(size);
  try {
    byte b1 = 123;
    mem.writeByte(addr, b1);
    byte b2 = mem.readByte(addr);
    assertEquals(b1, b2);
    byte b3 = 11;
    mem.writeByteVolatile(addr, b3);
    assertEquals(b3, mem.readByteVolatile(addr));
  }
  finally {
    mem.release(addr, size);
  }
}
origin: apache/ignite

/**
 * @param s String.
 * @throws Exception If failed.
 */
public void checkCompare(String s) throws Exception {
  byte[] bytes = s.getBytes();
  int size = bytes.length + 8;
  GridUnsafeMemory mem = new GridUnsafeMemory(size);
  for (int i = 0; i < 8; i++) {
    long addr = mem.allocate(size);
    long ptr = addr + i;
    try {
      mem.writeBytes(ptr, bytes);
      assert mem.compare(ptr, bytes);
      byte[] read = mem.readBytes(ptr, bytes.length);
      assert Arrays.equals(bytes, read);
    }
    finally {
      mem.release(addr, size);
    }
  }
}
origin: apache/ignite

/**
 * @throws Exception If failed.
 */
@Test
public void testInt() throws Exception {
  GridUnsafeMemory mem = new GridUnsafeMemory(64);
  int size = 32;
  long addr = mem.allocate(size);
  try {
    int i1 = 123;
    mem.writeInt(addr, i1);
    int i2 = mem.readInt(addr);
    assertEquals(i1, i2);
    int i3 = 321;
    mem.writeIntVolatile(addr, i3);
    int i4 = 222;
    assertTrue(mem.casInt(addr, i3, i4));
    assertFalse(mem.casInt(addr, i3, 0));
    assertEquals(i4, mem.readIntVolatile(addr));
  }
  finally {
    mem.release(addr, size);
  }
}
origin: apache/ignite

/**
 * @throws Exception If failed.
 */
@Test
public void testShort() throws Exception {
  GridUnsafeMemory mem = new GridUnsafeMemory(64);
  int size = 16;
  long addr = mem.allocate(size);
  try {
    short s1 = (short)56777;
    mem.writeShort(addr, s1);
    assertEquals(s1, mem.readShort(addr));
  }
  finally {
    mem.release(addr, size);
  }
}
origin: apache/ignite

/**
 *
 */
@Test
public void testFloat() {
  GridUnsafeMemory mem = new GridUnsafeMemory(64);
  int size = 32;
  long addr = mem.allocate(size);
  try {
    float f1 = 0.23223f;
    mem.writeFloat(addr, f1);
    assertEquals(f1, mem.readFloat(addr));
  }
  finally {
    mem.release(addr, size);
  }
}
origin: apache/ignite

/**
 *
 */
@Test
public void testDouble() {
  GridUnsafeMemory mem = new GridUnsafeMemory(64);
  int size = 32;
  long addr = mem.allocate(size);
  try {
    double d1 = 0.2323423;
    mem.writeDouble(addr, d1);
    assertEquals(d1, mem.readDouble(addr));
  }
  finally {
    mem.release(addr, size);
  }
}
origin: apache/ignite

GridUnsafeMemory mem = new GridUnsafeMemory(cap);
    boolean reserved = mem.reserve(block);
    long addr = mem.allocate(block, true, true);
    mem.release(addr, block);
assertEquals(mem.allocatedSize(), 0);
origin: apache/ignite

GridUnsafeMemory mem = new GridUnsafeMemory(0);
X.println("Alloc: " + mem.allocatedSize());
assertEquals(0, mem.allocatedSize());
origin: apache/ignite

boolean poll = !mem.reserve(size);
long addr = mem.allocate(size, false, true);
  mem.release(addr, size);
origin: apache/ignite

/**
 * @param ptr Pointer.
 * @param cnt Count.
 * @return Byte array.
 */
public byte[] readBytes(long ptr, int cnt) {
  return readBytes(ptr, new byte[cnt]);
}
origin: apache/ignite

/**
 * @param val String value.
 * @return List of strings are returned by readLine().
 * @throws IOException On error.
 */
List<String> readLineByHadoopDataInStream(String val) throws IOException {
  GridUnsafeMemory mem = new GridUnsafeMemory(0);
  HadoopDataOutStream out = new HadoopDataOutStream(mem);
  final long ptr = mem.allocate(BUFF_SIZE);
  out.buffer().set(ptr, BUFF_SIZE);
  out.write(val.getBytes());
  HadoopDataInStream in = new HadoopDataInStream(mem);
  in.buffer().set(ptr, out.buffer().pointer() - ptr);
  return readLineStrings(in);
}
origin: apache/ignite

/**
 * Reads address of next queue node.
 *
 * @param qAddr Queue node address.
 * @return Address of next queue node.
 */
private long next(long qAddr) {
  return mem.readLong(qAddr + 19);
}
origin: apache/ignite

      valBytes = mem.readBytes(cur + HEADER_SIZE + keyLen, valLen);
mem.release(relAddr, relSize);
origin: apache/ignite

/**
 * Reads entry hash code.
 *
 * @param qAddr Queue node address.
 * @return Entry hash code.
 */
private int hash(long qAddr) {
  return mem.readInt(qAddr + 6);
}
origin: apache/ignite

/**
 * @param jobInfo Job info.
 * @param mem Memory.
 */
public HadoopSkipList(HadoopJobInfo jobInfo, GridUnsafeMemory mem) {
  super(jobInfo, mem);
  heads = mem.allocate(HEADS_SIZE, true);
}
org.apache.ignite.internal.util.offheap.unsafeGridUnsafeMemory

Javadoc

Unsafe memory.

Most used methods

  • allocate
    Allocates memory of given size in bytes.
  • <init>
  • readByte
  • readBytes
  • release
    Releases memory at the given address.
  • writeByte
  • allocatedSize
  • casLong
  • readInt
  • readLong
  • readShort
  • writeBytes
    Writes part of byte array into memory location.
  • readShort,
  • writeBytes,
  • writeInt,
  • writeLong,
  • writeShort,
  • compare,
  • copyMemory,
  • readDouble,
  • readFloat,
  • readLongVolatile

Popular in Java

  • Running tasks concurrently on multiple threads
  • getSystemService (Context)
  • startActivity (Activity)
  • requestLocationUpdates (LocationManager)
  • FileReader (java.io)
    A specialized Reader that reads from a file in the file system. All read requests made by calling me
  • Time (java.sql)
    Java representation of an SQL TIME value. Provides utilities to format and parse the time's represen
  • Hashtable (java.util)
    A plug-in replacement for JDK1.5 java.util.Hashtable. This version is based on org.cliffc.high_scale
  • List (java.util)
    An ordered collection (also known as a sequence). The user of this interface has precise control ove
  • JPanel (javax.swing)
  • Table (org.hibernate.mapping)
    A relational table
  • Top plugins for Android Studio
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now