Native byte buffer is used to avoid double copy and zero initialization.
@@ -27,6 +27,8 @@ import com.orientechnologies.common.log.OLogManager;
import com.orientechnologies.common.serialization.types.OLongSerializer;
import com.orientechnologies.orient.core.config.OGlobalConfiguration;
import com.orientechnologies.orient.core.serialization.OBinaryProtocol;
+import com.sun.jna.Native;
+import com.sun.jna.Pointer;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -99,9 +101,14 @@ public class OFileClassic implements OFile, OClosableItem {
assert this.size >= size;
setSize(this.size);
- //noinspection resource
- final ByteBuffer buffer = ByteBuffer.allocate(size);
+ final long ptr = Native.malloc(size);
+ try {
+ final ByteBuffer buffer = new Pointer(ptr).getByteBuffer(0, size);
+ buffer.position(0);
OIOUtils.writeByteBuffer(buffer, channel, currentSize + HEADER_SIZE);
+ } finally {
+ Native.free(ptr);
+ }
return currentSize;
} finally {
