报警历史堆栈还是队列?

发布于 2024-08-11 09:33:35 字数 365 浏览 7 评论 0原文

我正在尝试开发一个警报历史结构来存储在非易失性闪存中。闪存的写入周期数量有限,因此我需要一种方法将记录添加到结构中,而无需每次都重写结构中的所有闪存页面或将更新的指针写出到队列的头/尾。

此外,一旦使用了可用的闪存空间,我想开始覆盖以前存储在闪存中的记录,从添加的第一条记录开始,先入先出。这让我认为循环缓冲区最适合添加项目。然而,当查看记录时,我希望结构像堆栈一样工作。例如,记录将以逆时间顺序后进先出的方式显示。

结构大小、头部、尾部、索引不能被存储,除非它们存储在记录本身中,因为如果每次将它们写出到固定位置,则会超过存储它们的页面上的最大写入周期。

那么我应该使用堆栈、队列还是某种混合结构?如何将头、尾、大小信息存储在flash中,以便上电后可以重新初始化?

I'm trying to develop an alarm history structure to be stored in non-volatile flash memory. Flash memory has a limited number of write cycles so I need a way to add records to the structure without rewriting all of the flash pages in the structure each time or writing out updated pointers to the head/tail of the queue.

Additionally once the available flash memory space has been used I want to begin overwriting records previously stored in flash starting with the first record added first-in-first-out. This makes me think a circular buffer would work best for adding items. However when viewing records I want the structure to work like a stack. E.g. The records would be displayed in reverse chronological order last-in-first-out.

Structure size, head, tail, indexes can not be stored unless they are stored in the record itself since if they were written out each time to a fixed location it would exceed the maximum write cycles on the page where they were stored.

So should I use a stack, a queue, or some hybrid structure? How should I store the head, tail, size information in flash so that it can be re-initialized after power-up?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

也只是曾经 2024-08-18 09:33:35

请参阅相关问题Flash 中的循环缓冲区

See a related question Circular buffer in Flash.

箜明 2024-08-18 09:33:35

查找 ring-buffer

假设您可以计算出哪个是最后一个条目(从时间戳等所以不需要写标记)这也具有最好的磨损均衡性能。

Lookup ring-buffer

Assuming you can work out which is the last entry (from a time stamp etc so don't need to write a marker) this also has the best wear leveling performance.

拥醉 2024-08-18 09:33:35

编辑:不适用于OP的闪光灯控制器:您不必担心磨损均衡。闪存控制器应该在幕后处理这个问题。

但是,如果您仍然想继续执行此操作,只需使用常规循环缓冲区,然后 保留指向栈头和栈尾的指针

您还可以考虑使用最近最少使用的缓存来管理闪存上存储数据的位置。

Edit: Doesn't apply to the OP's flash controller: You shouldn't have to worry about wear leveling in your code. The flash memory controller should handle this behind the scenes.

However, if you still want to go ahead an do this, just use a regular circular buffer, and keep pointers to the head and tail of the stack.

You could also consider using a Least Recently Used cache to manage where on flash to store data.

握住我的手 2024-08-18 09:33:35

你肯定需要一个环形缓冲区。但你是对的,元信息有点……有趣。

You definitely want a ring buffer. But you're right, the meta information is a bit...interesting.

傲娇萝莉攻 2024-08-18 09:33:35

将您的条目映射到几个部分。当这些部分已满时,从第一部分开始覆盖。添加序列号(nbr 序列号 > 2 * 条目),以便在重新启动时您知道第一个条目是什么。

Map your entries on several sections. When the sections are full, overwrite starting with the first section. Add a sequence-number (nbr sequence numbers > 2 * entries), so on reboot you know what the first entry is.

小兔几 2024-08-18 09:33:35

您可以做一个环形缓冲区的版本,其中存储在页面中的第一个元素是该页面被写入的次数。这使您可以通过查找数字低于上一页的第一页来确定下一步应该写入的位置。如果它们都相同,则从下一个数字开始。

You could do a version of the ring-buffer, where the first element stored in the page is number of times that page has been written. This allows you to determine where you should write next by finding the first page where the number is lower than the previous page. If they're all the same, you start from the beginning with the next number.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文