I'm not familiar with the libraries you are working with, but perhaps the "'non native', ie like a 'string', or 'vector'" issue is because they are not POD types?
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
Well I think I had plain old data confused with "things that need a deep copy; things for which a shallow copy would not suffice" -- that is, things that have dynamically-allocated memory rather than a simple array. Something like that.
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
First, I looked up a better description of POD . (This seems to say "yup" to your previous post.)
Unfortunately, that went over my head. (Was that a no, you can't use dynamically allocated datatypes, or yes, you can)And I found a better description of deep copy . But essentially, I believe I was saying no. I'll qualify that with: perhaps you may, but you'd need to make a deep copy.[?]
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
That's interesting because I found that if I was reading and writing from the shared memory inside the same program it worked, but when trying to read those special parts (string, vector) from another program, that's when it failed.
I'm venturing forth into the unknown a bit here, but I'll offer a guess. Here is some code that probably does things it shouldn't, but I'm using it as a prop for my guesses. (Doesn't that make it sound great.) :rolleyes:
#include <iostream>
#include <string>
#include <cstddef>
void showobject(const void *object, std::size_t size)
{
const unsigned char *byte = static_cast<const unsigned char *>(object);
for (size_t i = 0; i < size; ++i)
{
std::cout << std::hex << static_cast<int>(byte[i]);
}
std::cout << std::endl;
}
int main()
{
std::string text("hello world");
std::cout << text << " : ";
showobject(static_cast<const void *>(&text), sizeof text);
std::cout << text.c_str() << " : ";
showobject(static_cast<const void *>(text.c_str()), text.size());
std::cout << static_cast<const void *>(&text[0]) << std::endl;
return 0;
}
/* my output
hello world : 4454201000143b7b01000
hello world : 68656c6c6f20776f726c64
007B3B14
007B3B14
*/
You can kinda see that something in the string points to the memory that contains the actual string text.
Let's say that Program A and Program B share a string using shared memory. That means each shares the whole first line (of the output displayed). But Program A's memory is different from Program B's, so Program A points to a "hello world", but Program B's memory at 007B3B14 is different.
Anybody feel free to bail me out if I'm completely off target here.
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314