| ||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||
![]() |
原始链接: https://news.ycombinator.com/item?id=43456669
Hacker News 的讨论主题是 AttilaT 的“移向中间数组”(Shift-to-Middle Array),这是一种旨在替代 `std::deque` 的数据结构,它在两端插入和删除操作更快,并且改善了缓存局部性。它保持连续的内存布局,并将空闲空间重新分配到中间以减少数据移动。 早期的评论提出了关于处理非平凡类型(需要析构函数或移动构造函数)的担忧,建议使用 `static_assert` 检查。其他人则要求 `begin()/end()` 迭代器。 讨论将它与 gap buffer、环形缓冲区和 ExpandingRingBuffer 进行了比较,并对连续空闲空间和非空闲空间提出了疑问。orlp 分享了一个类似的、未完成的项目“devector”,并提出了不同的空闲空间管理策略,以优化内存使用并避免过度分配。讨论还涉及到移向中间数组相对于 `VecDeque`(连续内存)的潜在优势。 一位用户指出基准测试链接已损坏。
| ||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||
![]() |
- this is going to have problems with non-trivial types. (Think about destructors or move constructors like std::unique_ptr). If you don't want to deal with them, at least add a static_assert(std::is_trivially_copyable::value == true);
- front() doesn't return a reference and it doesn't even return the front
- adding iterators (begin()/end()) will let it play nice with for( : ) loops and, etc.
reply