/** * Free this {@link EpollEventArray}. Any usage after calling this method may segfault the JVM! */ void free() { Buffer.free(memory); memoryAddress = 0; }
void free() { Buffer.free(memory); memoryAddress = 0; }
/** * Release the {@link IovArray}. Once release further using of it may crash the JVM! */ public void release() { Buffer.free(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; } }
/** * 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); }
/** * 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; } } }
/** * Release the {@link IovArray}. Once release further using of it may crash the JVM! */ public void release() { Buffer.free(memory); }
/** * Free this {@link KQueueEventArray}. Any usage after calling this method may segfault the JVM! */ void free() { Buffer.free(memory); memoryAddress = size = capacity = 0; }
void free() { Buffer.free(memory); memoryAddress = 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; } }
/** * 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; } } }