私はBoost.Interprocessのドキュメントを何時間も見つめてきましたが、それでもこれを理解することができませんでした。ドキュメントには、次のように共有メモリにベクターを作成する例があります。
//Define an STL compatible allocator of ints that allocates from the managed_shared_memory.
//This allocator will allow placing containers in the segment
typedef allocator<int, managed_shared_memory::segment_manager> ShmemAllocator;
//Alias a vector that uses the previous STL-like allocator so that allocates
//its values from the segment
typedef vector<int, ShmemAllocator> MyVector;
int main(int argc, char *argv[])
{
//Create a new segment with given name and size
managed_shared_memory segment(create_only, "MySharedMemory", 65536);
//Initialize shared memory STL-compatible allocator
const ShmemAllocator alloc_inst (segment.get_segment_manager());
//Construct a vector named "MyVector" in shared memory with argument alloc_inst
MyVector *myvector = segment.construct<MyVector>("MyVector")(alloc_inst);
今、私はこれを理解しています。私が立ち往生しているのはsegment.construct()
、要素の数を指定するために2番目のパラメーターを渡す方法です。construct()
プロセス間ドキュメントは、としてのプロトタイプを提供します
MyType *ptr = managed_memory_segment.construct<MyType>("Name") (par1, par2...);
でもやってみると
MyVector *myvector = segment.construct<MyVector>("MyVector")(100, alloc_inst);
コンパイルエラーが発生します。
私の質問は次のとおりです。
- オブジェクトのコンストラクターである、
par1, par2
からパラメーターを実際に渡されるのは誰ですか。私の理解では、テンプレートアロケータパラメータが渡されています。あれは正しいですか?segment.construct
vector
alloc_inst
共有メモリに作成されているオブジェクトのコンストラクターに必要なパラメーターに加えて、別のパラメーターを追加するにはどうすればよいですか?
これに関する簡潔なBoostドキュメント以外の情報はほとんどありません。