boost :: interprocess :: managed_(windows_)shared_memory :: constructを使用して、メンバー変数を持つ独自のクラスを持つプロセス間ベクトルを構築しましたその型のstd :: stringと型のstdの別::ベクトル、の:boost :: interprocess - std :: string vs std :: vector
私はテストのためにこれをしなかったclass myclass
{
public:
myclass()
{
}
std::string _mystring;
std::vector <int> _myintvector;
};
template < class _type >
struct typedefs
{
typedef boost::interprocess::managed_windows_shared_memory _memory;
typedef _memory::segment_manager _manager;
typedef boost::interprocess::allocator < _type, _manager > _allocator;
typedef boost::interprocess::vector < _type, _allocator > _vector;
};
typedef typedefs <myclass> tdmyclass;
int main()
{
using namespace boost::interprocess;
managed_windows_shared_memory mem (open_or_create, "mysharedmemory", 65536);
tdmyclass::_vector * vec = mem.construct <tdmyclass::_vector> ("mysharedvector") (mem.get_segment_manager());
myclass mytemp;
mytemp._mystring = "something";
mytemp._myintvector.push_back (100);
mytemp._myintvector.push_back (200);
vec->push_back (mytemp);
/* waiting for the memory to be read is not what this is about,
so just imagine the programm stops here until everything we want to do is done */
}
は、私はどちらのstd ::文字列ものstd ::ベクトルがあれば、作業、まだすることが期待しました私は別のプロセスから読み込み、std :: stringは実際に動作し、それは私が割り当てた文字列を含んでいます。それは本当に私を驚かせた。 反対側のstd :: vectorは部分的にしか機能しませんが、size()によって返される値は正しいですが、イテレータにアクセスするか演算子[]を使用するとプログラムがクラッシュします。
だから私の質問は、どうしてそうですか?つまり、実際にはVisual StudioのSDKのSTL実装を読んだことはありませんが、std :: stringだけではなく、文字列に適した特別な関数を持つstd :: vectorですか?彼らはどちらもstd :: allocatorを使いません - どちらも、std :: stringとstd :: vectorは共用メモリでは動作しませんか?
これでグーグルすると、実際にはboost :: interprocess :: vector以外の結果は得られません。それは私が検索したものではありません。だから私は誰かが私に何かについての詳細を教えてくれることを願っています^^
PS:私は上記のコードでタイプミスをしてしまったのですが、私はこのページエディタでこれを書きました。私のIDEのオートコンプリートに使用されています^
正確に。したがって、長い文字列では機能しません。それをチェックしてください:_) – sehe
大変感謝しています^^私は期待したとおりにstd :: vectorが動作することを忘れていました^^しかしSSOから何も聞いたことはありません^^ – Andy