boost进程间内存分配缓慢
它看起来像这样:
MyType * pMy = my_segment->construct<MyType>(anonymous_instance)();
my_segment->destroy_ptr(pMy);
其中 MyType 是一些典型的结构,并且 my_segment 是正确构造的 boost::interprocess::managed_shared_memory * 比同等速度慢大约 10 倍:
MyType * pMy = new MyType();
delete pMy;
我没想到会这样。我认为这两种分配算法在实现和性能上应该相似。如此巨大的差异有什么充分的理由吗?
编辑:测试是经过大量迭代进行的。
It looks like this:
MyType * pMy = my_segment->construct<MyType>(anonymous_instance)();
my_segment->destroy_ptr(pMy);
Where MyType is some typical struct and my_segment is correctly constructed boost::interprocess::managed_shared_memory *
is around 10 times slower than the equivalent:
MyType * pMy = new MyType();
delete pMy;
I did not expect this. I though the two allocation algorithms should be similar in implementation and performance. Is there some good reason for such a huge difference.
Edit: The test was conducted over a huge number of iterations.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试多次分配,看看它们是否都很慢或只有第一个分配很慢。如果只有第一个速度慢,可能是因为支持共享内存的页面需要提交(而不仅仅是保留)。如果页面已提交,则可能仍需要对其进行分页(从页面/交换文件)。
除了初始分配之外的任何缓慢,都可以归因于高度调整的自由存储分配器(即新的)与 boost 用于管理共享内存段中的“分配”的机制(例如,boost 可能使用可移植且更昂贵的同步)序列化分配的机制)。
Try multiple allocations and see if they are all slow or only the first. If only the first is slow, it could be because the page backing the shared memory needs to be committed (and not just reserved). If the page is commited it might still potentially have to be paged in (from the page/swap file).
Any slowness baring the initial allocation, can be attributed to a highly tuned free-store allocator (i.e., new) vs the mechanism that boost uses to manage "allocations" in the shared memory segment (e.g., boost might use portable and more expensive synchronization mechanism to serialize allocations).