I’d like to read a binary file with a few 32 bit float values at byte offset 31.
Unfortunately, new Float32Array(buffer, 31, 6); does not work. An offset of 32 instead of 31 works but I need 31.
According to this page, offset has to be a multiple of the element size, 4 in this case.
I’m interested in the reason behind this behaviour. Why does it matter where the view starts?
The best workaround I found thus far has not made it into gecko yet so I can’t use it.
Do I realy have to cut and copy the byte values into a new array to get my float values?
Some architectures do not allow unaligned word accesses, and there are performance penalties on architectures that do allow it such as x86 (though some instructions must be aligned).
Yes, just like Markus’ example you should create a new
ArrayBufferwith aUInt8Arrayview and aFloat32Arrayview for aread_buffer(copy withUInt8Arrayview and interpret fromFloat32Arrayview). Then you can read from your data with aUInt8Array, copy that into yourread_bufferview and then interpret using theFloat32Array. It’s quite a seamless process.