Boost.Flyweight内存消耗
我正在阅读一篇关于 Boost 的文章 .Flyweight性能
正如您在链接中看到的,工厂的开销是
- 对于 hashed_factory
:~2.5 * sizeof(word)
- for set_factory
: 4 * sizeof(word)
基本问题是.... 为什么 set 是 4 个单词而不是 0 ?
据我所知,使用哈希意味着计算和存储哈希键,而使用集合则不然:它是作为红黑树实现的,插入和查找需要 log(n),因此不存储任何值,并且内存开销应该为零(缺点是,在哈希的情况下,您将进行 log(n) 比较,而不是进行一次比较)。错误在哪里?
I'm just reading an article about Boost.Flyweight Performance
As you can see in the link the overhead of the factory is
- for hashed_factory
: ~2.5 * sizeof(word)
- for set_factory
: 4 * sizeof(word)
The basic question is .... why 4 words for set and not zero ?
As far as I know, using a hash implies computing and storing a hash key, while using a set not: it's implemented as a red-black-tree, inserting and look-up takes log(n), so no values is stored and memory overhead should be zero (with the drawback that instead of one comparison in the case of hash you will have log(n) comparisons). Where is the mistake ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
RB树的每个节点包含一个指向左子节点的指针、一个指向右子节点的指针、颜色和一条数据。前三个算作开销,这意味着它不是 0。我不太清楚为什么他们说它是 4,因为 3 个元素很容易容纳在 3 个单词中,但也许它们算在其他东西中(比如父节点指针,这并不是绝对必要的,也不是内存分配开销,尽管这不太可能)。
Each node of the RB tree contains a pointer to the left child, pointer to the right child, the color and one piece of data. The first three count as overhead, which means it isn't 0. I'm not quite sure why they say it's 4 when the 3 elements fit easily in 3 words, but maybe they count in something else (like the parent node pointer, which isn't strictly necessary, or memory allocation overhead, although that's unlikely).