|
Boost Users : |
Subject: Re: [Boost-users] Mutex synchronised wrapper class for boost::interprocess shared memory vector of strings
From: Ion Gaztañaga (igaztanaga_at_[hidden])
Date: 2013-06-24 15:40:19
El 19/06/2013 23:10, Riskybiz escribió:
> I'm now having trouble reading from the vector in the shared memory. I get
> an exception when calling read(0) or read(1). What I'm trying to do is read
> "testing testing 123" from the first element of the sharedSegmentVector.
> Is it necessary to use some particular type conversion technique in the
> reader function to access a sharedSegmentVector string element? Any help to
> get this working is much appreciated; I've been trying for more than a month
> to get to this point! Code below.....
I just glanced but I don't see anything wrong in your code, but you are
creating temporaries in your read function, this can be optimized.
Something like:
//Reader
std::string read(long index)
{
scoped_lock<named_mutex> lock(*m_mutex);
const MyShmString & shmStr =
(*sharedSegmentVector)[index];
std::string stdStr(shmStr.begin(), shmStr.end());
return stdStr;
}
Just make sure the sharedSegmentVector->size() is bigger or equal than
"index". Try to go step by step with the debugger to see what's really
happening in your function, if the crash is due to an exception is
thrown, or something else.
Ion
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