/** * Increase the storage of this {@link EpollEventArray}. */ void increase() { // double the size length <<= 1; // There is no need to preserve what was in the memory before. ByteBuffer buffer = Buffer.allocateDirectWithNativeOrder(calculateBufferCapacity(length)); Buffer.free(memory); memory = buffer; memoryAddress = Buffer.memoryAddress(buffer); }
public IovArray() { memory = Buffer.allocateDirectWithNativeOrder(CAPACITY); memoryAddress = Buffer.memoryAddress(memory); }
/** * Free this {@link EpollEventArray}. Any usage after calling this method may segfault the JVM! */ void free() { Buffer.free(memory); memoryAddress = 0; }
} else { ByteBuffer nioBuffer = buf.internalNioBuffer(buf.readerIndex(), len); return add(Buffer.memoryAddress(nioBuffer), nioBuffer.position(), len); final int len = nioBuffer.remaining(); if (len != 0 && (!add(Buffer.memoryAddress(nioBuffer), nioBuffer.position(), len) || count == IOV_MAX)) { return false;
/** * Returns the size of a pointer. */ public static int addressSize() { if (PlatformDependent.hasUnsafe()) { return PlatformDependent.addressSize(); } return addressSize0(); }
/** * Returns the memory address of the given direct {@link ByteBuffer}. */ public static long memoryAddress(ByteBuffer buffer) { assert buffer.isDirect(); if (PlatformDependent.hasUnsafe()) { return PlatformDependent.directBufferAddress(buffer); } return memoryAddress0(buffer); }
KQueueEventArray(int capacity) { if (capacity < 1) { throw new IllegalArgumentException("capacity must be >= 1 but was " + capacity); } memory = Buffer.allocateDirectWithNativeOrder(calculateBufferCapacity(capacity)); memoryAddress = Buffer.memoryAddress(memory); this.capacity = capacity; }
void free() { Buffer.free(memory); memoryAddress = 0; }
} else { ByteBuffer nioBuffer = buf.internalNioBuffer(buf.readerIndex(), len); return add(Buffer.memoryAddress(nioBuffer), nioBuffer.position(), len); final int len = nioBuffer.remaining(); if (len != 0 && (!add(Buffer.memoryAddress(nioBuffer), nioBuffer.position(), len) || count == IOV_MAX)) { return false;
/** * Returns the size of a pointer. */ public static int addressSize() { if (PlatformDependent.hasUnsafe()) { return PlatformDependent.addressSize(); } return addressSize0(); }
/** * Returns the memory address of the given direct {@link ByteBuffer}. */ public static long memoryAddress(ByteBuffer buffer) { assert buffer.isDirect(); if (PlatformDependent.hasUnsafe()) { return PlatformDependent.directBufferAddress(buffer); } return memoryAddress0(buffer); }
private void reallocIfNeeded() { if (size == capacity) { // Double the capacity while it is "sufficiently small", and otherwise increase by 50%. int newLength = capacity <= 65536 ? capacity << 1 : capacity + capacity >> 1; ByteBuffer buffer = Buffer.allocateDirectWithNativeOrder(calculateBufferCapacity(newLength)); // Copy over the old content of the memory and reset the position as we always act on the buffer as if // the position was never increased. memory.position(0).limit(size); buffer.put(memory); buffer.position(0); Buffer.free(memory); memory = buffer; memoryAddress = Buffer.memoryAddress(buffer); capacity = newLength; } }
NativeLongArray(int capacity) { if (capacity < 1) { throw new IllegalArgumentException("capacity must be >= 1 but was " + capacity); } memory = Buffer.allocateDirectWithNativeOrder(calculateBufferCapacity(capacity)); memoryAddress = Buffer.memoryAddress(memory); this.capacity = capacity; }
/** * Release the {@link IovArray}. Once release further using of it may crash the JVM! */ public void release() { Buffer.free(memory); }
/** * Increase the storage of this {@link KQueueEventArray}. */ void realloc(boolean throwIfFail) { // Double the capacity while it is "sufficiently small", and otherwise increase by 50%. int newLength = capacity <= 65536 ? capacity << 1 : capacity + capacity >> 1; try { ByteBuffer buffer = Buffer.allocateDirectWithNativeOrder(calculateBufferCapacity(newLength)); // Copy over the old content of the memory and reset the position as we always act on the buffer as if // the position was never increased. memory.position(0).limit(size); buffer.put(memory); buffer.position(0); Buffer.free(memory); memory = buffer; memoryAddress = Buffer.memoryAddress(buffer); } catch (OutOfMemoryError e) { if (throwIfFail) { OutOfMemoryError error = new OutOfMemoryError( "unable to allocate " + newLength + " new bytes! Existing capacity is: " + capacity); error.initCause(e); throw error; } } }
EpollEventArray(int length) { if (length < 1) { throw new IllegalArgumentException("length must be >= 1 but was " + length); } this.length = length; memory = Buffer.allocateDirectWithNativeOrder(calculateBufferCapacity(length)); memoryAddress = Buffer.memoryAddress(memory); }
/** * Free this {@link KQueueEventArray}. Any usage after calling this method may segfault the JVM! */ void free() { Buffer.free(memory); memoryAddress = size = capacity = 0; }
private void reallocIfNeeded() { if (size == capacity) { // Double the capacity while it is "sufficiently small", and otherwise increase by 50%. int newLength = capacity <= 65536 ? capacity << 1 : capacity + capacity >> 1; ByteBuffer buffer = Buffer.allocateDirectWithNativeOrder(calculateBufferCapacity(newLength)); // Copy over the old content of the memory and reset the position as we always act on the buffer as if // the position was never increased. memory.position(0).limit(size); buffer.put(memory); buffer.position(0); Buffer.free(memory); memory = buffer; memoryAddress = Buffer.memoryAddress(buffer); capacity = newLength; } }
public IovArray() { memory = Buffer.allocateDirectWithNativeOrder(CAPACITY); memoryAddress = Buffer.memoryAddress(memory); }
/** * Release the {@link IovArray}. Once release further using of it may crash the JVM! */ public void release() { Buffer.free(memory); }