2 ms·
> why you might not want to use byte[] Such as? Java buffers use byte arrays by default as underlying storage.
by kaba0 4y ago
> why you might not want to use byte[]
Such as? Java buffers use byte arrays by default as underlying storage.
- klodolph 4y agohttps://docs.oracle.com/javase/7/docs/api/java/nio/ByteBuffer.html https://docs.oracle.com/javase/7/docs/api/java/nio/ByteBuffe... Look for "Direct vs. non-direct buffers". Some buffers are backed by arrays, some are not. You're basically deciding whether you are okay with a higher cost for I/O or a higher-cost for interacting with the data in the buffer.
- kaba0 4y agoI do know about it, I was trying to find out what difference do the parent mean between Go’s byte arrays and Java’s solution(s). Also, I fail to get your conclusion — direct buffers only have a higher cost for initialization/dealloc otherwise reading/writing should be as cheap as it gets. Byte buffers on the other hand do get write barriers but that is also unlikely to be hit that often (and I believe larger byte arrays get allocated in a separate region that doesn’t get moved).