I want to convert a byte array to double and am doing this using the following code -
double fromByteArraytoDouble(byte[] bytes) {
return ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN).getDouble();
}
This code works, but I call this function in repeated iterations in my android app. (The loop is actually a background process that keeps running.) The wrap() function supposedly creates a new object everytime it is called and therefore after a few execution cycles the android garage collector runs to clean up the memory (I got this info from DDMS) -
D/dalvikvm(6174): GC_FOR_ALLOC freed 2K, 5% free 12020K/12580K, paused 15ms, total 15ms
This pauses the code for some milliseconds which is unacceptable for the app. Is there a way to do the conversion of the byte array to double without using ByteBuffer?