高效的 C 池分配器?
我目前正在尝试用 C 语言编写 2D 场景图,并且需要决定存储子节点的方式。我期望有很多读取和很少写入,因此由于引用的空间局部性较差,因此链表是不可能的,并且每次添加子节点时使用 realloc
可能会导致空闲碎片列入遗忘名单。池分配器似乎是最好的解决方案,但我似乎找不到任何可以使用的实现。有谁知道一个分配器可以有效地处理数百个小型结构的随机分配和取消分配,或者可能是更好的分配方案?
I'm currently attempting to write a 2D scene graph in C, and I need to decide on a way of storing the child nodes. I'm expecting very many reads and few writes, so a linked list is out of the question due to poor spatial locality of reference, and using realloc
every time to add a child node would probably fragment the free list into oblivion. A pool allocator seems to be the best solution, but I can't seem to find any implementations to use. Does anyone know of an allocator that would efficiently handle random-ish allocations and deallocations of a few hundred small struct
s, or perhaps a better allocation scheme?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我正准备将 TLSF 部署为实时分配器。我还没有机会分析它的性能,但它似乎有效,并且 许可证是正确的。
根据他们的文档,其操作“在 x86 架构中最多执行 168 条处理器指令”。它以单个 .c 文件形式出现,在我的系统上无需修改即可编译。
I'm preparing to deploy TLSF as a real-time allocator. I haven't had a chance to profile its performance yet, but it seems to work, and the license is right.
According to their docs, its operations execute "a maximum of 168 processor instructions in a x86 architecture". It comes as a single .c file, which compiled without modifications on my system.
看看halloc,它可能会有所帮助。
http://swapped.cc/halloc/
Take a look at halloc, it might be of some help.
http://swapped.cc/halloc/