2010-03-13 2 views
2

몇 시간 동안 Boost.Interprocess 문서를 보았지만 아직 파악하지 못했습니다. doc 후, 그들은과 같이 공유 메모리에 벡터를 만드는 an example 있습니다Boost.Interprocess의 manage_shared_memory.construct()에 매개 변수를 전달하는 방법

//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()에 전달하여 요소 수를 지정하는 방법입니다. 프로세스 간 문서는 내가

MyVector *myvector = segment.construct<MyVector>("MyVector")(100, alloc_inst); 

을하려고하면 컴파일 에러가 발생 construct()

MyType *ptr = managed_memory_segment.construct<MyType>("Name") (par1, par2...); 

로하지만에 대한 프로토 타입을 제공합니다.

내 질문은 : 실제로 매개 변수 segment.construct에서 par1, par2, 객체의 생성자, 예를 전달됩니다

  1. vector? 내 이해 템플릿 할당 자 매개 변수를 전달하는 것입니다. 그 맞습니까?
  2. alloc_inst 이외에 공유 메모리에서 생성되는 개체의 생성자에 필요한 다른 매개 변수를 추가하려면 어떻게해야합니까?

여기에 간략한 부스트 문서 이외의 정보는 거의 없습니다.

답변

3

부스트 사용자 메일 링리스트와 Steven Watanabe replied에 대해서도 같은 문제가 생겼습니다. std :: vector에는 형식 (크기, 할당 자)의 생성자가 없습니다. 내가 생성자가

vector (size_type n, const T& value= T(), const Allocator& = Allocator()); 

것을 볼 해당 설명서를 보면 그렇게 올바른 호출

MyVector *myvector = segment.construct<MyVector>("MyVector")(100, 0, alloc_inst); 

초등학교해야한다, 내 사랑, 왓슨, 초등!