Algorithm for converting binary array to char array in Java (without using objects like Double.toString or StringBuilder)?
Does anyone know where I can find this algorithm? It takes a double and a StringBuilder and adds a double to the StringBuilder without creating any objects or garbage. Of course I'm not looking for:
sb.append(Double.toString(myDouble));
// or
sb.append(myDouble);
I've tried scrolling through the Java source code (I'm sure it is anyway), but I couldn't see any block of code / logic clear enough to be reused.
source to share
I wrote this for ByteBuffer. You must be able to adapt it. Writing it to a straight ByteBuffer allows you to convert it to bytes or copy it to native space.
Cm. public ByteStringAppender append(double d)
If you log this to a file, you can use the entire library, as it can write about 20 million doubles per second. It can do this without system calls since it writes to a memory mapped file.
source to share