... without copying.
public class AirCompressorVMCrash {
public static void main(String[] args) {
var deallocation = new ConcurrentLinkedQueue<Arena>();
Thread.ofPlatform().daemon().start(() -> {
do {
Arena arena;
if ((arena = deallocation.poll()) != null) arena.close();
} while (true);
});
var compressor = new ZstdJavaCompressor();
var input = createInput();
var maxCompressedLength /* not 64-bit? */ = compressor.maxCompressedLength(/* not 64-bit? */ Math.toIntExact(input.byteSize()));
do {
var arena = Arena.ofShared();
var output = arena.allocate(maxCompressedLength);
deallocation.offer(arena);
compressor.compress(input, output);
} while (true);
}
private static MemorySegment createInput() {
var b = new byte[655356];
new SecureRandom().nextBytes(b);
return MemorySegment.ofArray(b);
}
}