Re: [Boost-users] Accessing memory in shared segments
From: Andy Falanga (afalanga) Sent: Thursday, June 27, 2013 7:42 AM To: 'boost-users@lists.boost.org' Subject: Accessing memory in shared segments
Hi,
I have some code which shares data with shared memory. To that end, I'm using >boost::interprocess:managed_shared_memory. Without respect to scope and functions, what I have is >roughly:
boost::interprocess::managed_shared_memory sharedMem(boost::interprocess::create_only, "SharedMemory", 4096);
//later on u_int8_t* dataSegment = sharedMemory.construct
("data")[5](0); char* string1 = sharedMemory.construct<char>("String 1")[50]('\0'); // other stuff // placing stuff in the data segment for(int i(0); i < 5; i++) dataSegment[i] = anEarlierArray[i];
// then, in other process read the data Segment char ary[5]; for(int i(0); i< 5; i++) ary[i] = dataSegment.first[i];
For whatever reason I couldn't simply access through dataSegment[n] notation. The weirdest thing is, >the data is being read back to me in the reverse order that it should be. For example, if [0x2,0x4,0x7,0x1] is written I read it back as [0x1,0x7,0x4,x02] even though I'm writing and reading >in the same order. Why is this? What is it I'm missing about using shared memory?
Problem solved: it was between the keyboard and the chair. Further debugging showed that the data wasn't being written in reverse (it made no sense that it would have been) but rather was a result of some HID libraries I'm using under the hood. Posting this in case someone hits on this message while looking through the archives. Andy
participants (1)
-
Andy Falanga (afalanga)