Esmond Pitt <esmond.pitt@nospam.bigpond.com> wrote:
The only time writing a struct from memory to a file or a network can
Who is talking about writing data to a network?
sanely be justified is when the target application is constructed
with the same version of the same object file that wrote it. And
this is not a guarantee that in general can be met.
Uh, this is pretty much what I just said other than I see no need for
the "guarantee" part - it is not necessary unless the *intent* is to
distribute the data externally.
As I said, my gripe is in calling the originator of the OP's data
clueless. That statement is simply clueless itself. Yes, if the
original program had been written in Java, then maybe that statement
would be true. But this
is a C++ program. The data files are most likely "private", only to
be used internally. Sure, if you port the code to another platform,
the binary files between the two versions may not be compatible, but
so what - that usually isn't a problem. The new code will create
binary files that are compatible with itself. Creating some external
specification that this binary data must meet would be stupid because
then, if you did port the code, now you may have to modify it to be
compatible with the original specification, and this may require more
processing of the data. Suddenly, some specification is driving
internal data, and robbing some degree of performance from the
application.
compiler) would cause an incompatibility. The good news is that compiler
vendors tend not to change struct layouts for that very reason. Still, this
made.
number. If it never changes, you've added a small amount of overhead. When