我应该使用升压快池分配为以下? [英] Should I use boost fast pool allocator for following?

查看:120
本文介绍了我应该使用升压快池分配为以下?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在整个24小时的过程中不断增加新的项目到一组服务器。元素不超过24期内删除,只是新的元素不断被插入。

I have a server that throughout the course of 24 hours keeps adding new items to a set. Elements are not deleted over the 24 period, just new elements keep getting inserted.

然后,在期末集合被清除,新的元素开始得到再次增加了24小时。

Then at end of period the set is cleared, and new elements start getting added again for another 24 hours.

你认为一个快速池分配会在这里有用的重用内存,并可能不成帮助?

Do you think a fast pool allocator would be useful here as to reuse the memory and possibly help with fragmentation?

这组增长到100万左右的元素。每个元素都是1K左右。

The set grows to around 1 million elements. Each element is about 1k.

推荐答案

这是极不可能......但你当然可以自由测试它在你的程序。

It's highly unlikely …but you are of course free to test it in your program.

对于规模和分配格局的集合(多!多!多!+成长!成长!成长!),你应该使用向量的数组。只要将它保存在连续的块和储备()当他们创建,你永远需要重新分配/调整或浪费空间和带宽遍历列表。载体将是最适合你的内存布局的集合大。没有一个大的载体(这将需要很长的时间来调整),但有几个载体,每个重present块(理想的块大小可以通过平台有所不同 - 我与5MB开始每从那里测量)。如果你跟着,你看有没有需要调整或重新使用的内存;只是创建一个分配每隔几分钟在未来 N 对象 - 有没有需要高频率/速度对象分配和娱乐

For a collection of that size and allocation pattern (more! more! more! + grow! grow! grow!), you should use an array of vectors. Just keep it in contiguous blocks and reserve() when they are created and you never need to reallocate/resize or waste space and bandwidth traversing lists. vector is going to be best for your memory layout with a collection that large. Not one big vector (which would take a long time to resize), but several vectors, each which represent chunks (ideal chunk size can vary by platform -- I'd start with 5MB each and measure from there). If you follow, you see there is no need to resize or reuse memory; just create an allocation every few minutes for the next N objects -- there is no need for high frequency/speed object allocation and recreation.

有关池分配的事情会建议你想了很多具有不连续的分配,大量的插入和删除喜欢大的分配名单的对象 - 这是不好的几个原因。如果你想创建这在这个尺寸优化了连续分配的实现,只需要瞄准与向量的方法块。分配和查找都将接近微乎其微。在这一点上,分配时间应该是微小的(相对于你做的其他工作)。那么你也将有没有什么不寻常或令人惊讶的关于你的分配模式。然而,快速的池分配建议你把这个集合作为一个列表,这将有此问题的可怕表现。

The thing about a pool allocator would suggest you want a lot of objects which have discontiguous allocations, lots of inserts and deletes like a list of big allocations -- this is bad for a few reasons. If you want to create an implementation which optimizes for contiguous allocation at this size, just aim for the blocks with vectors approach. Allocation and lookup will both be close to minimal. At that point, allocation times should be tiny (relative to the other work you do). Then you will also have nothing unusual or surprising about your allocation patterns. However, the fast pool allocator suggests you treat this collection as a list, which will have terrible performance for this problem.

一旦实施该块+向量方法,更好的性能比较(在这一点上)将是比较刺激的pool_allocator VS的std ::分配器。当然,你可以测试所有三个,但内存碎片很可能会,如果你正确地执行它被更由向量方法,减少了块。 参考

Once you implement that block+vector approach, a better performance comparison (at that point) would be to compare boost's pool_allocator vs std::allocator. Of course, you could test all three, but memory fragmentation is likely going to be reduced far more by that block of vectors approach, if you implement it correctly. Reference:

如果你是认真地关注性能,容器等的std ::列表打交道时使用fast_pool_allocator,并使用pool_allocator与容器比如std :: vector的问题时。

If you are seriously concerned about performance, use fast_pool_allocator when dealing with containers such as std::list, and use pool_allocator when dealing with containers such as std::vector.

这篇关于我应该使用升压快池分配为以下?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆