/** * Mark entry as being polled or not. * * @param qAddr Queue node address. * @param polling Polling flag. */ private void polling(long qAddr, boolean polling) { mem.writeByte(qAddr + 10, (byte)(polling ? 1 : 0)); }
/** * 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; }
/** * @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); } }
/** * 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; }
/** {@inheritDoc} */ @Override public void writeByte(byte b) throws IOException { if (bufPosition == bufLength) { currBufIdx++; switchCurrentBuffer(); } crc.update(b); mem.writeByte(currBuf + bufPosition++, b); }
/** {@inheritDoc} */ @Override public void writeByte(int v) { mem.writeByte(move(1), (byte)v); }
/** * Mark entry as being polled or not. * * @param qAddr Queue node address. * @param polling Polling flag. */ private void polling(long qAddr, boolean polling) { mem.writeByte(qAddr + 10, (byte)(polling ? 1 : 0)); }
/** {@inheritDoc} */ @Override public void writeByte(byte b) throws IOException { if (bufPosition == bufLength) { currBufIdx++; switchCurrentBuffer(); } crc.update(b); mem.writeByte(currBuf + bufPosition++, b); }