Re: structs for data transfer?
From: nospam (nospam_at_example.com)
Date: 09/20/04
- Next message: Rich Grise: "Re: Can I delete without calling the destructor ?"
- Previous message: Sims: "Re: std::vector erase is not freeing mem?"
- In reply to: Oliver Gerlich: "structs for data transfer?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 19 Sep 2004 18:22:48 -0400
Oliver Gerlich wrote:
> I have doubts about this (because of data packing, and because
> sizeof(bool) might be inconsistent between compilers...), but I'm not
> sure...
Yes you are right :-)
1. You can not be sure not only about bool, but also about byte order(endian
type) and int size.
2. Worst than that, there may be alignament difference into the elements of
the stuct.
What you have to do is to "serialize" data for sending and "deserialize" for
receiving. Doing that means to define some rules about how each data type
is converted into a byte array and back.
> Can someone tell me if this concept is right or wrong? Or has someone a
> better solution for this problem (maybe something else than structs)?
You can always send a structure safelly, after you have defined a method of
serialization of that struct :-)
If you have time, a good book to read it will be Stevens "Unix Network
Programming" for a clear ideea about sockets.
- Next message: Rich Grise: "Re: Can I delete without calling the destructor ?"
- Previous message: Sims: "Re: std::vector erase is not freeing mem?"
- In reply to: Oliver Gerlich: "structs for data transfer?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|