• And pictoral:

    `
    :Space managment bytes         :Data storage bytes                     :
    :1st      2nd     n-th last    :1st blck          n-block      last blk:
    :76543210 765 \\ 43210 76543210:                                       :
    .--------.--- // -----.--------.--------.--------.--- // -----.--------.
    |11111111|111 \\ 11111|11111111|ffffffff|ffffffff|fff \\ fffff|ffffffff|
    '--x-----'--- // -----'-------x'--------'--------'--- // -----'--------'
     ^^|                          | ^                              ^
     |||                          | |    'points' to last block    |
     |||                          '-)------------------------------'
     ||| 'points' to first block    |
     ||'----------------------------'
     ||
     |'---: 1/0 page to keep / to clear (for reuse)
     '----: 1/0 page has space / is full
    `
    

    Ic. - Make's sense since you are interested only in the miles / kms you completed.

    My approach is a general one: while thinking about the things beyond the completed miles/kms, like time and other items you might want to take notes for later graphing - speed, direction, altitude, coordinates, temperatures (ambient, batteries, motor, charge states,...), the algorithm stays the same... only the data block grows in size and every block includes a time stamp. Adding a time stamp lets you optimize the memory usage, because you write back only on 'significant' changes...

    The reason to use the bits in the byte the reverse order - from MSB to LSB - is to simplify the code: starting with a compare byte that has the MSB set and then shift right while set bit still in compare byte and (&&) 'and' (&) is false. When the while loop ends and the compare byte still has 'the' bit then that's the space.

About

Avatar for allObjects @allObjects started