simoncarter2003
Programmer
Im using stringstreams to serialize and unserialize an instance of my class to send it over a network. However I've encountered an access violation when I try to pass my unserialized object between functions.
The serialization and unserialization of my objects seems to work correctly, and after the unserialization I can call functions from within the class and it works as it should do. But when I pass this new object to a different function I get the access violation error; note however that this doesn't happen if I don't call the .read() function into the object prior though.
From researching on the Internet, I *think*, that this is because I'm having to use a char* conversion because I'm using the .read() function, and the compiler is therefore putting my object into read only memory, and therefore I get my violation error when writing is attempted to the memory location.
So I have two questions: If my understanding of the error is correct, how can I prevent it being placed in read-only memory. And if I can't how can I copy this object into a different object thats in standard memory.
My error is: "0xC0000005: Access violation writing location 0x73696854."
Thanks in advance,
Simon
The serialization and unserialization of my objects seems to work correctly, and after the unserialization I can call functions from within the class and it works as it should do. But when I pass this new object to a different function I get the access violation error; note however that this doesn't happen if I don't call the .read() function into the object prior though.
From researching on the Internet, I *think*, that this is because I'm having to use a char* conversion because I'm using the .read() function, and the compiler is therefore putting my object into read only memory, and therefore I get my violation error when writing is attempted to the memory location.
So I have two questions: If my understanding of the error is correct, how can I prevent it being placed in read-only memory. And if I can't how can I copy this object into a different object thats in standard memory.
Code:
Datagram Handler::UnserializeDatagram(std::string strin, int size) {
std::istringstream strstream(strin);
Datagram Message;
strstream.read((char*)&Message, sizeof(Message));
return Message;
}
My error is: "0xC0000005: Access violation writing location 0x73696854."
Thanks in advance,
Simon