I am working on a project where I generate data that initially occupies 17 bytes, and I compress it down to 3 bytes. These 3 bytes are then stored in a Uint8Array, as shown in the code snippet below:
var buffer = new Uint8Array(3);
buffer[0] = deltaTimestamp;
buffer[1] = (deltaElevation >> 8) & 0xff;
buffer[2] = deltaElevation & 0xff;
I've noticed that this 3-byte array is taking up 3 blocks in memory, with each block being 14 bytes on my system. When I write this array to a binary file, the size of the file is just 3 bytes, as expected.
I would like to understand why this 3-byte array is consuming 3 blocks instead of being represented within a single block, and if there's a way to optimize this. Any insights would be greatly appreciated. Thank you!
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
I am working on a project where I generate data that initially occupies 17 bytes, and I compress it down to 3 bytes. These 3 bytes are then stored in a Uint8Array, as shown in the code snippet below:
I've noticed that this 3-byte array is taking up 3 blocks in memory, with each block being 14 bytes on my system. When I write this array to a binary file, the size of the file is just 3 bytes, as expected.
I would like to understand why this 3-byte array is consuming 3 blocks instead of being represented within a single block, and if there's a way to optimize this. Any insights would be greatly appreciated. Thank you!