How to pass parameters to manage_shared_memory.construct() in Boost.Interprocess

I've stared at the Boost.Interprocess documentation for hours but
still haven't been able to figure this out. In the doc, they have of
creating a vector in shared memory like so:
//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

AMDG Cuneyt Taskiran wrote:
The interprocess document gives the prototype for `construct()` as
MyType *ptr = managed_memory_segment.construct<MyType>("Name") (par1, par2...); but when I try
MyVector *myvector = segment.construct<MyVector>("MyVector")(100, alloc_inst); I get compilation errors.
This is because vector doesn't have such a constructor. Try (100, 0, alloc_inst) In Christ, Steven Watanabe

Steven Watanabe
AMDG
Cuneyt Taskiran wrote:
The interprocess document gives the prototype for `construct()` as
MyType *ptr = managed_memory_segment.construct<MyType>("Name") (par1, par2...); but when I try
MyVector *myvector = segment.construct<MyVector>("MyVector")(100, alloc_inst); I get compilation errors.
This is because vector doesn't have such a constructor. Try (100, 0, alloc_inst)
In Christ, Steven Watanabe
Works like a charm, thanks a lot! I checked std::vector doc and saw that it's constructor is explicit vector ( size_type n, const T& value= T(), const Allocator& = Allocator() ); so you're right. Stupid question: if this is the constructor, how does std::vector<int> v = std::vector<int>(100) work? Thanks a lot, C

AMDG Cuneyt wrote:
Works like a charm, thanks a lot! I checked std::vector doc and saw that it's constructor is explicit vector ( size_type n, const T& value= T(), const Allocator& = Allocator() ); so you're right. Stupid question: if this is the constructor, how does std::vector<int> v = std::vector<int>(100) work?
The value and allocator parameters have defaults. In Christ, Steven Watanabe

Hi, I have application that is using boost program option library. If I provide unknown option via CLI it should throw exception. The library is statically linked on windows and Linux environment. It works fine on windows platform I do get exception for unknown CLI option. On Linux platform I get "segfault" in place of exception for unknown CLI option. It is s a multi-threaded application and it also uses boost thread library. Application does throw exception on Linux also if I link dynamically. I am using following flags to link the library statically: LDFLAGS= -fexceptions -static-libgcc -Wl,-static -L/usr/lib -lboost_program_options-gcc41-mt -lboost_filesystem-gcc41-mt -lboost_thread-gcc41-mt -lboost_system-gcc41-mt -lnet7ssh -lbotan -ltar -lz -lrt -lpthread I am using following version of gcc: # g++ --version g++ (GCC) 4.1.1 Copyright (C) 2006 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Here is the core dump for the segfault: (gdb) backtrace #0 __gnu_internal::get_global () at /usr/software/src/gcc-4.1.1/libstdc++-v3/libsupc++/eh_globals.cc:58 #1 0x082c0f67 in __cxa_get_globals () at /usr/software/src/gcc-4.1.1/libstdc++-v3/libsupc++/eh_globals.cc:71 #2 0x082c0b3f in __cxa_allocate_exception (thrown_size=32) at /usr/software/src/gcc-4.1.1/libstdc++-v3/libsupc++/eh_alloc.cc:154 #3 0x080a71f8 in boost::program_options::detail::cmdline::finish_option () #4 0x080a77eb in boost::program_options::detail::cmdline::run () #5 0x0806f3aa in boost::program_options::basic_command_line_parser<char>::run () #6 0x080660e9 in CLIHandler::collectCLIOptions () #7 0x0808a0d1 in perfstat::runPerfstat () #8 0x0808af3d in main () Current language: auto; currently c++ Appreciate your help Regards, NG
participants (4)
-
Cuneyt
-
Cuneyt Taskiran
-
Neetu Garg
-
Steven Watanabe