Hello,
Please can somebody help me on this code (from boost site). I try to run
it but I still get the following error:
*/cygdrive/C/Program Files/NetBeans 7.1.2/ide/bin/nativeexecution/dorun.sh:
line
33: 12900 Segmentation fault (core dumped) sh "${SHFILE}"
Press [Enter] to close the terminal ...*
This is the code for creating vector in shared memory:
#include
#include
#include
#include <string>
#include <cstdlib> //std::system
using namespace 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
ShmemAllocator;
//Alias a vector that uses the previous STL-like allocator so that allocates
//its values from the segment
typedef vector MyVector;
//Main function. For parent process argc == 1, for child process argc == 2
int main(int argc, char *argv[])
{
if(argc == 1){ //Parent process
//Remove shared memory on construction and destruction
struct shm_remove
{
shm_remove() { shared_memory_object::remove("MySharedMemory"); }
~shm_remove(){ shared_memory_object::remove("MySharedMemory"); }
} remover;
//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);*
* ;*
}
else{
// some code
}
return 0;
};
I got an error for this instruction: *MyVector *myvector =
segment.construct<MyVector>("MyVector")(alloc_inst);
*This addition information about the environnment: NetBeans 7.1.2 with
Cygwin_4.x, gcc-core 3.4.4-999,
gcc-g++ 3.4.4-999,gcc-mingw-core 20050522-3,gcc-mingw-g++
20050522-3 ,gcc4-core 4.5.3-3 ,
gcc4-g++ 4.5.3-3 , gdb 7.5.50-1. I am using Windows XP SP3.
Many thanks.
--
Regards
Austina