Re: How to serialize Mfc template dialog class ?

Tech-Archive recommends: Fix windows errors by optimizing your registry



See below...
On Thu, 10 Sep 2009 00:03:55 -0700 (PDT), Goran <goran.pusic@xxxxxxxxx> wrote:

On Sep 8, 3:31 pm, Joseph M. Newcomer <newco...@xxxxxxxxxxxx> wrote:
Now do this with data structures that are very rich and which have been modified for ten
years.

Hi!

I tried imagining how some soft of "tagged" data (I am guessing,
similar to XML, you are trying to push for some sort of id<->value
mapping for any particular n-tuple of data (a struct or a class) can
help significantly better than e.g. serialization and I can't see it.
****
Because when you read a tag, and the data structure does not support it, you know that you
have to reject the value (or do something else with it). In serialization, the assumption
is that the values are positional and therefore the n-to-n+3 bytes MUST be the int value
'count', but under schema migration you actually have no guarantee, so you have to assume
that it is correct; if it isn't, you are screwed. Or, you have to be able to serialize by
using the structure that was defined in the earlier version, which means you now have a
"version managaement" problem with no tools to help you manage it; you have to manage the
many versions of your data structure from witiin your code structure, for example, by
knowing that in versions < 3, it was the count, but for versions >=3 and <5 it was the
offset, and versions >=5 and < 9 it was the bit mask of valid data, and versions >=9 it is
something else again. The code gets pretty ugly.
****

Here's what I imagine (I am focusing on reading, because writing is
easier anyhow; I am also focusing on one n-tuple because everything
else, e.g. containers or other sorts of composition seem to be a
matter of putting bricks together):

If you have random access e.g. DOM of XML (I think, if you have
sequential access a là SAX of XML, things only get closer to
serialization), reading consists of getting out a value based on the
desired attribute, e.g.

member1 = value(attr1); member2 = value(attr2); ...

What this gives over serialization is random read order. That gives
possibility to skip "unknown" data items without using my "unused
idiom". In the light of small schema changes (which IMO in
overwhelming majority are additions to the n-tuple), that doesn't buy
much, either. One can alleviate missing attributes (get_value(member,
attr) and nothing is done if there's no attribute), avoiding if
(schema>=x) {} nesting. But that comes at a price of having bigger
"infrastructure"^^^.
****
If you believe all schema changes are small, fine, but I've found that every few years
there is a major schema redesign in far too many programs (hence the three-year watershed
where they realize they have painted themselves into a corner)
****

Now... As far for "major" overhauls, I fail to see how "tagged data"
can avoid my step 3 from up here ("upon loading, if "global" version
is BOOM-1 and less, load obsolete data, then "convert" to new data
model"). It does avoid step 2, and there is hidden only major
conceptual advantage I can see: stored data is clearly disconnected
from data model present in the code. But again, that comes at a price
of having bigger "infrastructure". It should be noted that even with
serialization, he who is smart does not tie serialized "data model"
more than necessary with the rest of the code (incidentally, for the
most part that isn't my case :-( ).
****
It doesn't help in the conversion, but it does result in simpler code to handle it. The
"bigger infrastructure", e.g., using XML, is a trivial cost to pay for the simplification.

Binary-tagged data works well in the case you describe. And it decouples reading from
structure, in that reading the bytes n..n+3 does not tie the meaning to offset n of the
structure. Instead, you read a tag (which can actually be an integer local to the
individual structure: I am tag 4 of the XyZZy structure) and know that the next 4 bytes
after the tag are always the count. If the count-in-bytes is changed to a count-in-words
for some reason, the tag number changes. If the count is dropped, you can ignore the tag.
If the structure morphs to something completely different (it now contains a
std::vector<T> instead of a compile-time constant T[SOME_FIXED_SIZE] it makes no
difference, because the type was not serialized by some mechanism that requires you have
to know the type to deserialize it; instead, the types used in the serialization are
defined solely by the serialization. Only for external types do you use the external type
serialization (e.g., for embedded OLE objects) and even then there would be a tag saying
"I am an embedded chart", which would tell you to use the chart serialization to read it
in).

For complex graphs, we had a mechanism that allowed them to be expressed as text, and it
only had to be written and tested once. We then used it for another six years. XML has a
similar provision.
joe
****

^^^ infrastructure that which one doesn't do at all with
serialization - big amount of stuff is already there, e.g. container
serialization, schema support, very easy low-level primitives a là >>
and << etc. What serialization also offers is easy serialization of
complicated data graphs (doing ar <</>> p for one value of p in
multiple places results in correct p instance being read back). That's
something many are not aware of and comes in quite handy. Doable with
any other approach, sure, but again, a thing to write (and test).

?

Goran.
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages

  • Re: xmlns=> was not expected.
    ... > deserialization on this xml and get the results. ... It's not possible to serialize/deserialize this based on serialization ... This method needs to return an XML Schema ...
    (microsoft.public.dotnet.xml)
  • Re: dateTime in Web Services
    ... The Special Case of XML ... Simply because the XML encoding for a DateTime ... When we start with a local time, the result of serialization (encode to ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Cant read CString after serialization
    ... Joe, that -was- XML. ... parse the file and show it (for example, a columnar display of tag id, tag ... The serialization mechanism of MFC template containers like CArchive is ...
    (microsoft.public.vc.mfc)
  • Re: Retain default attribute values after XSD Validation?
    ... >> when I serialize the resulting doc using its WriteContentTo method, ... >> the default attributes are NOT represented in the XML output stream. ... It could generate an XML serialization preserving as much of the ... I'll want to digitally sign the Account element to both ...
    (microsoft.public.dotnet.xml)
  • Re: lxml/ElementTree and .tail
    ... switching to well-understood XML subsets or other serialization ... formats, simpler and more flexible data models, simpler API:s, and ... At the serialization level, it's easy to think that CDATA sections are different from other text, that character references are different from ordinary characters, that you should ...
    (comp.lang.python)