|
Boost Users : |
Subject: Re: [Boost-users] Information about create_only and open_or_create
From: manish4gupta (manish_at_[hidden])
Date: 2009-10-22 22:46:07
Process1.cpp
#include <boost/interprocess/managed_shared_memory.hpp>
#include <boost/interprocess/allocators/allocator.hpp>
#include <boost/interprocess/containers/map.hpp>
#include <boost/interprocess/containers/string.hpp>
#include <iostream>
#include <vector>
#include <fstream>
using namespace boost::interprocess;
typedef managed_shared_memory::segment_manager segment_manager_t;
typedef allocator<void, segment_manager_t> void_allocator;
typedef allocator<char, segment_manager_t> char_allocator;
typedef basic_string<char, std::char_traits<char>, char_allocator>
char_string;
typedef std::pair<const char_string, char_string> map_value_type;
typedef allocator<map_value_type, segment_manager_t>
map_value_type_allocator;
typedef multimap< char_string, char_string, std::less<char_string>,
map_value_type_allocator> complex_map_type;
std::string trim(const char *str)
{
std::string ptr;
int i,j=0;
for(i=0;str[i]!='\0';i++)
{
if (str[i] != ' ' && str[i] != '\t')
ptr += str[i];
}
return ptr;
}
int main (int argc, char* argv[])
{
using namespace std;
const char* MySharedMemory= "MySharedMemory";
shared_memory_object::remove(MySharedMemory); // It works
fine but when put on comment then
managed_shared_memory segment(open_or_create,MySharedMemory, 999999999);
void_allocator alloc_inst (segment.get_segment_manager());
complex_map_type *mymap =
segment.construct<complex_map_type>("MyMap")(std::less<char_string>(),
alloc_inst);
std::cout << mymap->size() << std::endl;
ifstream in(argv[1]);
char line[1000];
char recline[100];
int index = 0;
while(in)
{
in.getline(line,1000);
int len = strlen(line);
strcpy(recline,line);
if(in)
{
std::stringstream ss;
//std::cout << index << endl;
ss<< index;
char name[1000];
strcpy(name, "1:");
std::cout << name << endl;
char* pch;
pch = strtok(line,"\t");
vector <const char*> vec;
while(pch != NULL)
{
vec.push_back(pch);
pch = strtok(NULL,"\t");
}
std::string y = trim(vec[vec.size()-1]);
std::cout << y << endl;
char_string cs(y.c_str(), alloc_inst);
strcat(name, (ss.str()).c_str());
char_string indexvalue(name, alloc_inst);
std::cout << cs << "\t" << indexvalue << std::endl;
mymap->insert(std::pair<char_string, char_string>(cs,indexvalue));
index += len;
index += 1;
}
}
return 0;
}
It works fine if i create a new sharedmemroy and use it but when i run this
code again by putting comment on
shared_memory_object::remove(MySharedMemory) to use the existing
Sharedmemory and map in it.
Exception
terminate called after throwing an instance of
'boost::interprocess::interprocess_exception'
what(): boost::interprocess_exception::library_error
Aborted
What is the reason for this? And how can i overcome such pblm? Thanks in
advance.
Christoph Gysin-3 wrote:
>
> 2009/10/22 manish4gupta <manish_at_[hidden]>:
>> I am working on shared memory. I am successful in using it but I am
>> trying
>
> Please provide more detailed information about your problem. Add a
> short (compilable) example demonstrating the problem, including the
> complete error message. Also provide information about your operating
> system, compiler, etc...
>
> Don't just post the same question again. Thanks.
>
> Chris
> --
> echo mailto: NOSPAM !#$.'<*>'|sed 's. ..'|tr "<*> !#:2" org_at_fr33z3
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
>
-- View this message in context: http://www.nabble.com/Information-about-create_only-and-open_or_create-tp25902079p26020156.html Sent from the Boost - Users mailing list archive at Nabble.com.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net