batchTmp = NativeBytesStore.lazyNativeBytesStoreWithFixedCapacity(maxMsgSize); long lengthCount = batchAppender.writeMessages(batchTmp.addressForWrite(0), maxMsgSize, 1); int len = (int) lengthCount; dc.wire().bytes().write(batchTmp, (long) Integer.BYTES, len - Integer.BYTES);
long start = System.nanoTime(); long count = 0; nbs = NativeBytesStore.nativeStoreWithFixedCapacity(size); nbs.release(); long mid = System.nanoTime(); long time1 = mid - start;
private static long writeMessages(long address, long canWrite, int writeCount) { long length = 0; long count = 0; // writeCount = writeCount == 1 ? 1 : ThreadLocalRandom.current().nextInt(writeCount-1)+1; long fromAddress = nbs.addressForRead(0); while (writeCount > count && length + 4 + size <= canWrite) { UnsafeMemory.UNSAFE.copyMemory(fromAddress, address + 4, size); UnsafeMemory.UNSAFE.putOrderedInt(null, address, size); address += 4 + size; length += 4 + size; count++; } // System.out.println("w "+count+" "+length); return (count << 32) | length; } }
/** * Allocate a fixed size buffer read for writing. * * @param capacity minimum to allocate * @return a new Bytes ready for writing. */ static VanillaBytes<Void> allocateDirect(long capacity) throws IllegalArgumentException { @NotNull NativeBytesStore<Void> bs = NativeBytesStore.nativeStoreWithFixedCapacity(capacity); try { return bs.bytesForWrite(); } finally { bs.release(); } }
public BytesMatrix(int maxRows, int columns) { this.maxRows = maxRows; this.columns = columns; long size = calcSize(maxRows, columns); bytes = NativeBytesStore.lazyNativeBytesStoreWithFixedCapacity(size); bytes.writeInt(MAX_ROWS_OFFSET, maxRows); bytes.writeInt(USED_ROWS_OFFSET, 0); bytes.writeInt(COLUMNS_OFFSET, columns); }
public InMemoryLongColumn(TimeSeries timeSeries, String name, BytesLongLookup lookup, long capacity) { super(timeSeries, name); this.lookup = lookup; long value = lookup.sizeFor(capacity); this.bytes = Jvm.isDebug() ? Bytes.wrapForRead(ByteBuffer.allocateDirect(Math.toIntExact(value))) : NativeBytesStore.lazyNativeBytesStoreWithFixedCapacity(value); }
static Bytes<ByteBuffer> elasticByteBuffer(int initialCapacity, int maxSize) { @NotNull NativeBytesStore<ByteBuffer> bs = NativeBytesStore.elasticByteBuffer(initialCapacity, maxSize); try { return bs.bytesForWrite(); } finally { bs.release(); } }
@NotNull @Override @ForceInline public Bytes<Underlying> writeDoubleAndInt(double d, int i) { long offset = writeOffsetPositionMoved(12); bytesStore.writeDouble(offset, d); bytesStore.writeInt(offset + 8, i); return this; }
@NotNull public static <T> NativeBytesStore<T> uninitialized() { return new NativeBytesStore<>(); }
@Test public void testFacarde() { IFacade f = Values.newNativeReference(IFacade.class); Byteable byteable = (Byteable) f; long capacity = byteable.maxSize(); byteable.bytesStore(NativeBytesStore.nativeStore(capacity), 0, capacity); System.out.println(f); }
@NotNull @Override @ForceInline public NativeBytesStore<Underlying> write( long writeOffset, @NotNull RandomDataInput bytes, long readOffset, long length) throws BufferOverflowException, BufferUnderflowException { if (bytes.isDirectMemory()) { memory.copyMemory(bytes.addressForRead(readOffset), addressForWrite(writeOffset), length); } else { write0(writeOffset, bytes, readOffset, length); } return this; }
@Override @ForceInline public double readDouble(long offset) { return bytesStore.readDouble(offset); }
public void set(int row, int column, double value) { long index = index(row, column); bytes.writeDouble(index, value); }
@Override public long addressForWrite(long offset) throws BufferOverflowException { return bytesStore.addressForWrite(offset); }
private BytesStore allocateBytesStoreForInstance() { long instanceSize = nativeInstance.maxSize(); if (instanceSize > Bytes.MAX_BYTE_BUFFER_CAPACITY) { return NativeBytesStore.nativeStoreWithFixedCapacity(instanceSize); } else { return BytesStore.wrap(ByteBuffer.allocate(Maths.toUInt31(instanceSize))); } }
private NativeBytesStore(@NotNull ByteBuffer bb, boolean elastic) { init(bb, elastic); }
@Override public void ensureCapacity(long capacity) { long cap = lookup.sizeFor(capacity); if (cap > bytes.realCapacity()) { long value = lookup.sizeFor(capacity); BytesStore bytes2 = Jvm.isDebug() ? Bytes.wrapForRead(ByteBuffer.allocateDirect(Math.toIntExact(value))) : NativeBytesStore.lazyNativeBytesStoreWithFixedCapacity(value); bytes2.write(0, bytes); bytes.release(); bytes = bytes2; } }
@NotNull public static NativeBytesStore<ByteBuffer> elasticByteBuffer(int size, long maxSize) { return new NativeBytesStore<>(ByteBuffer.allocateDirect(size), true); }
@Override public void init(JLBH jlbh) { IOTools.deleteDirWithFiles("replica", 10); Byteable byteable = (Byteable) datum; long capacity = byteable.maxSize(); byteable.bytesStore(NativeBytesStore.nativeStore(capacity), 0, capacity); datumBytes = ((Byteable) datum).bytesStore(); datumWrite = datumBytes.bytesForWrite(); sourceQueue = single("replica").build(); sinkQueue = single("replica").build(); appender = sourceQueue.acquireAppender(); tailer = sinkQueue.createTailer(); this.jlbh = jlbh; }
public double get(int row, int column) { long index = index(row, column); return bytes.readDouble(index); }