Closed LogicAndTrick closed 7 years ago
Actually, it might be a good idea to rewrite everything to use ByteBuffer
, but there are quite a few traps along the way.
First of all, I'd like to start rewriting Java runtime with a solid benchmarking suite, to be able to measure which is actually faster or slower.
ByteBuffer can be be used even for reading things directly from local memory-mapped file. I've heard that it's really mapped to underlying mmap
, if OS supports it, so it would be very fast on Linux and Solaris, but it may come down to slow emulation sometimes (Windows?) and in these cases regular Java buffered inputs work faster.
Also, ByteBuffer has a totally different implementation on Android - and it's a good idea to benchmark it too.
There are also a few interesting alternatives like using Unsafe
- http://senior-java-developer.com/unsafe/ or even https://github.com/airlift/slice
I found Java's
ByteBuffer
class which supports converting byte arrays into float/double - it looks like it's got native support for short/int/long as well. Should we change all thereadS
methods to use theByteBuffer
class? Seems more maintainable than the hand-coded method. There's no built-in methods to deal with unsigned types so thereadU
methods will still need to be manual.