Re: is it ok to use c++ STL containers like string inside a structure
and pass in message ques?
On Feb 4, 2:14 pm, SG <s.gesem...@gmail.com> wrote:
On 4 Feb., 10:59, ashjas <ash...@gmail.com> wrote:
I tried to use string containers inside a structure and pass
it in message queue to recieve at other end...but got
different kinds of errors..segmentation fault..junk values
etc...
Sounds like you just copy a struct byte by byte. This won't
work for all kinds of objects. For those it'll work we say
they are "trivially copyable".
Formally, there are no "trivially copyable" objects in C++, at
least not in this sense. "Trivially copyable" (e.g.
memcpy'able) only works within the program; not between
programs.
In practice, you can often count on bytes being 8 bits on both
ends, so arrays of unsigned char, or even char, are "trivially
copiable". Everything else needs to be serialized in some form
or another.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34