/** * Resizes this {@code DirectStore} to the {@code newSize}. * * <p>If {@code zeroOut} is {@code false}, the memory past the old size is not zeroed out and will * generally be garbage. * * <p>{@code DirectStore} don't keep track of the child {@code DirectBytes} instances, so after * the resize they might point to the wrong memory. Use at your own risk. * * @param newSize new size of this {@code DirectStore} * @param zeroOut if the memory past the old size should be zeroed out on increasing resize * @throws IllegalArgumentException if the {@code newSize} is not positive */ public void resize(long newSize, boolean zeroOut) { if (newSize <= 0) throw new IllegalArgumentException("Given newSize is " + newSize + " but should be positive"); address = deallocator.address = NativeBytes.UNSAFE.reallocateMemory(address, newSize); if (zeroOut && newSize > size) { NativeBytes.UNSAFE.setMemory(address + size, newSize - size, (byte) 0); } size = newSize; }
public DirectStore(ObjectSerializer objectSerializer, long size, boolean zeroOut) { this.objectSerializer = objectSerializer; address = NativeBytes.UNSAFE.allocateMemory(size); // System.out.println("old value " + Integer.toHexString(NativeBytes.UNSAFE.getInt(null, // address))); if (zeroOut) { NativeBytes.UNSAFE.setMemory(address, size, (byte) 0); NativeBytes.UNSAFE.putLongVolatile(null, address, 0L); } this.size = size; deallocator = new Deallocator(address); cleaner = Cleaner.create(this, deallocator); }