Leon Mergen wrote:
I wondered how the Boost.Serialization library determines how many bytes to read from an input stream to "fill" a class with data.
That is, does it read an entire input stream until the end of the stream and use that as the data to fill a class with, or does it perform a sizeof(class) and read that from the stream ?
Neither. Each class has its serialize function. Within this function it calls the operator << to copy the member data to archive. There are two cases: a) the data type is a primitive - int, etc - in which case the archive has method for storing it and knows the length of an int on the particular platform. b) the datatype is a class - in which case that class's serialize function is called. So eventually the serialization resolves to a string of calls to primitive types - all of which are supported by the archive class.
If it is the latter, then out of curiosity, how does it determine the size of an object with different class versions ( so if an object version 1 has been saved and then tries to load version
The first piece of data stored with the class is a version number. On loading, this is available to be used in conditional ar >> operations. When one adds a new member to the class - the version number should be updated so that the loading of new member can be skipped if the archive is an older version. 2 ) ? Does it write some sort of object size at the beginning of the file ? no.
If it reads the entire stream until the end,
None of the currently implmented archive classes do this.
what would be a good approach to save multiple objects in a single file, and be able to read just a few objects out of the file ?
Current archive classes don't support a good way to do this. Actually this is an iteresting application - but its not supported by current archives. One might be able make a new archive class or a new derivation from one of the existing ones to support this, but I have no idea how difficult it would be. At a minium it would require a pretty thorough understanding of the library and archive classes.
Thanks in advance for any responses.
you're welcome. Robert Ramey