保持固定大小的符号共享内存 [英] Keeping fixed size symbols in shared memory
问题描述
我一直在努力一些东西,我需要存储符号列表和相应的数量,这些被存储为一个字符串,整数的映射。问题是输入的大小约为32 MB但是当我试图将其存储在内存中的大小来腌支持速度高达1.4Gb,我通过几个环节去了,发现的std ::字符串占用的内存相当数量的记账和很容易造成臃肿,所以我看起来有点进一步发现,人们可以使用升压::数组大小等于符号的最大尺寸,并且由于升压阵列没有做任何的书保持它doesn' ŧ导致内存膨胀。
不过,我希望把这个升压数组中像共享内存中,以便地图<升压::数组<焦炭,15>
,int>的。我看了看升压::阵列文档,发现它不支持分配器,目前我使用的分配器和段经理从boost如下:
I have been working on something which requires me store the list of symbols and the corresponding count, these are being stored as a string,int mapping. The problem is the input size is around 32 MB however when I try to store it in memory the size bloats to 1.4Gb, I went through a few links and found that std::string takes up a fair amount of memory for book keeping and is likely to cause the bloat, so I looked a little further and found that one could use the boost::array with a size equal to the max size of the symbol and since the boost array doesn't do any book keeping it doesn't cause memory bloat.
However, I wish to place this boost array in the shared memory like so map<boost::array<char, 15>
, int>.I took a look at the boost::array documentation and found that it doesn't support allocators, currently I am using allocators and segment managers from boost as follows:
typedef bip::allocator<char, bip::managed_shared_memory::segment_manager> CharAllocator;
typedef bip::basic_string<char, std::char_traits<char>, CharAllocator> SharedString;
我也遇到了这个环节,这似乎解释了很多:
http://jovislab.com/blog/?p=89
有没有办法做到这一点,有什么,我有其他选择。我不是在寻找完整的解决方案,但提示。
谢谢,
德布!
Is there a way to do this, what are the other choices that I have. I am not looking for complete solutions, but hints. Thanks, Deb!
推荐答案
适当的提示是:
- 使用连续分配
- 储备达阵
这答案包含升压managed_shared_memory不同的分配技术好的一面并排比较:
This answer contains a good side-by-side comparison of different allocation techniques with Boost managed_shared_memory:
在您的特定情况下,你可以通过扁平化的分配
In your particular case you could flatten the allocation by using
-
flat_map
和 - 对于字符串使用池分配(或者使用
的boost :: string_ref
指从大型分配的字符串的std ::矢量&lt;字符&GT ;
)
flat_map
and- use pool allocator for the strings (or perhaps use
boost::string_ref
to refer to strings allocated from on largestd::vector<char>
)
这篇关于保持固定大小的符号共享内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!