user156224
Member since Aug 2023 • Last active Feb 2024Most recent activity
-
- 13 comments
- 648 views
-
Thank you for the detailed explanation; it all makes sense now! I've included my code below where I store data in the "compressedData = []" array. Is there a way to save this data with fewer storage blocks or space?
var lastTimestamp = 1692048524472; var lastElevation = 0; var compressedData = []; function compressData(sample) { // Split sample into timestamp and elevation var parts = sample.split("/"); var timestamp = parts[0]; var elevation = Math.round(parseFloat(parts[1]) * 100); // Calculate deltas var deltaTimestamp = (timestamp - lastTimestamp) / 10; // Time difference in tenths of milliseconds var deltaElevation = elevation - lastElevation; // Mask values deltaTimestamp &= 0xff; deltaElevation &= 0xffff; // Create buffer with 1 byte for timestamp delta and 2 bytes for elevation delta var buffer = new Uint8Array(3); buffer[0] = deltaTimestamp; buffer[1] = (deltaElevation >> 8) & 0xff; buffer[2] = deltaElevation & 0xff; console.log("size = " + E.getSizeOf(buffer)); console.log("remaining blocks = " +process.memory().free); // Update last values lastTimestamp = timestamp; lastElevation = elevation; compressedData.push.apply(compressedData, buffer); } setInterval(function(){ compressData("1692048525472/294.35") },500); //the output is this: size = 3 remaining blocks = 11820 size = 3 remaining blocks = 11817 size = 3 remaining blocks = 11814 size = 3 remaining blocks = 11811 size = 3 remaining blocks = 11808 size = 3 remaining blocks = 11805 size = 3 remaining blocks = 11802
-
-
-
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!
Thank you both...you really helped me a lot with your explanations.