Java Code Examples for io.netty.util.internal.PlatformDependent#setMemory()

The following examples show how to use io.netty.util.internal.PlatformDependent#setMemory() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ByteUtil.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
private static void uncheckedZeros(final ByteBuffer buffer, int offset, int bytes) {
   if (buffer.isReadOnly()) {
      throw new ReadOnlyBufferException();
   }
   final byte zero = (byte) 0;
   if (buffer.isDirect() && PlatformDependent.hasUnsafe()) {
      PlatformDependent.setMemory(PlatformDependent.directBufferAddress(buffer) + offset, bytes, zero);
   } else if (buffer.hasArray()) {
      //SIMD OPTIMIZATION
      final int arrayOffset = buffer.arrayOffset();
      final int start = arrayOffset + offset;
      Arrays.fill(buffer.array(), start, start + bytes, zero);
   } else {
      //slow path
      for (int i = 0; i < bytes; i++) {
         buffer.put(i + offset, zero);
      }
   }
}
 
Example 2
Source File: UnsafeByteBufUtil.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
static void setZero(long addr, int length) {
    if (length == 0) {
        return;
    }

    PlatformDependent.setMemory(addr, length, ZERO);
}
 
Example 3
Source File: NIOSequentialFileFactory.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public void clearBuffer(final ByteBuffer buffer) {
   if (buffer.isDirect()) {
      PlatformDependent.setMemory(PlatformDependent.directBufferAddress(buffer), buffer.limit(), (byte) 0);
   } else {
      Arrays.fill(buffer.array(), buffer.arrayOffset(), buffer.limit(), (byte) 0);
   }
}
 
Example 4
Source File: UnsafeByteBufUtil.java    From netty-4.1.22 with Apache License 2.0 4 votes vote down vote up
static void setZero(byte[] array, int index, int length) {
    if (length == 0) {
        return;
    }
    PlatformDependent.setMemory(array, index, length, ZERO);
}