Circular Buffer in Flash

前端 未结 5 1845
悲&欢浪女
悲&欢浪女 2021-01-02 18:25

I need to store items of varying length in a circular queue in a flash chip. Each item will have its encapsulation so I can figure out how big it is and where the next item

5条回答
  •  隐瞒了意图╮
    2021-01-02 19:13

    Keep a separate block that contains a pointer to the start of the first record and the end of the last record. You can also keep more information like the total number of records, etc.

    Until you initially run out of space, adding records is as simple as writing them to the end of the buffer and updating the tail pointer.

    As you need to reclaim space, delete enough records so that you can fit your current record. Update the head pointer as you delete records.

    You'll need to keep track of how much extra space has been freed. If you keep a pointer to end of the last record, the next time you need to add a record, you can compare that with the pointer to the first record to determine if you need to delete any more records.

    Also, if this is NAND, you or the flash controller will need to do deblocking and wear-leveling, but that should all be at a lower layer than allocating space for the circular buffer.

提交回复
热议问题