Re: saving std::string to a file

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




The next time you do a redesign, you might consider making all of your
classes derive from some common base class that has Serialize and
Deserialize methods. Then, you can write a CPoint::Serialize that knows
how to write the object to a stream, and a CPoint::Deserialize that knows
how to recreate the object from a stream. Once you do that, you won't be
dependent on the internal format. You could change the struct to use a
std::string, as long as the Serialize function writes the length first.
--
Tim Roberts, timr@xxxxxxxxx
Providenza & Boekelheide, Inc.

Hi Tim,
My main concern is char becoming obsolete.
It's an interesting approach you suggested because that's how I was doing it
in the first place.
I was looping through the array and each CPoint was saving itself., but as
the array became bigger, serializing became slower until I had to look at
it. The easy fix was to just write the whole array in one go.
I guess I could have optimised in other areas, but it was quick and allowed
me to get on with other things.

Anyway, thanks for confirming that using std:string has those limitations.

Ron.


.



Relevant Pages

  • Re: Serializing data set with de-normalized data
    ... You have very limited ability to affect the XML output and the only things ... array, you'll need to create each of those values and separate them with ... some delimmiter and ultimately treat them as one value. ... ComplexType and define your own effective Array, that should serialize ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: serialize only a litte part?
    ... BAIS: byte array input stream ... BAOS: byte array output stream ... Yes you can serialize only a part. ...
    (comp.lang.java.programmer)
  • Re: Serialize/DeSerialize Generics List
    ... a bit of a brain fart there: I said "Deserialize" when I meant ... "Serialize" a bunch of times. ... from Array. ... converted to-and-from your hidden List property (converting from lists ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Dynamic serialization of objects with lists or pointers as members
    ... referenced by a pointer to the base class, ... And some of these classes have an array as a member. ... 1- If I want to call each object's serialize() function, ... thenI don't know what will happen when I try to store ...
    (microsoft.public.vc.mfc)
  • Serialize and Unserializa weird behaviour
    ... I found a strange behaviour using serialize and unserialize to persist ... to file a configuration array. ... I'm using a flat text file to store configuration information. ...
    (php.general)