
Peter Dimov wrote:
Robert Ramey wrote:
Changing the names a little bit for clarity, I always anticipated archive developers would use something like the following:
template<class T> void save(boost::hpc_archive &ar, const std::valarray<T> & t...) { const unsigned int count = t.size(); ar << count; save_array(ar, get_data(t),t.size()); }
This would apply the save_array enhancement to all classes derived from hpc_archive. In fact I would expect that this is the way people are doing it now.
This doesn't work well for several reasons. First, the static type of ar is hpc_archive, so hpc_archive must be a polymorphic archive base, and this is not desirable since it's High Performance.
The motivating use case for this discussion has been a benchmark which uses save_array to replace 1000000000 invocations of save_binary which write one byte each with one invocation of save_binary to write 100000000 bytes. I doubt that the overhead related to one call through a virtual function table will be very significant here. Second, its not clear that it will always need to be a virtual function Actually I was thinking that the default implementation of save_array for hpc_oarchive would be just to invoke save_binary. Any derived classes - e.g. MPI_oarchive or whatever would implement there own versions. So one would have template<class T> void save(boost::MPI_archive &ar, const std::valarray<T> & t...) { // assuming save_binary isn't a good implementation // use another one. ... } Since the serialization libary templates make calls through the most derived class, I would expect the appropriate function to be invoked without going through any virtual function table.
Second, if you add an overload for std::vector:
template<class T> void save(boost::hpc_archive &ar, const std::vector<T> & t...)
the version in the Serialization library will take precedence since it's an exact match for the archive argument, and the overload above requires a derived to base conversion.
Hmmm the version in the serialization library looks like:
template<class Archive, class T> void save(Archive &ar, const std::vector<T> & t...)
I was pretty sure that a conversion from a derived class to a base would take precedence of the more general case - Now I'm not so sure. I double check this.
Even if it did work, I don't see in which circumstances a class author would like to _not_ take advantage of the save_array enhancement.
LOL, its impossible to predict things like this. We can't think of everything ahead of time.
Ideally, he should just call save_array in save, without restricting it to a specific set of archives. I don't see what you gain by denying him this opportunity
I know it seems attractive and its just "One Nore Small Little Thing" and if it were the "Last Thing" I might be able to see it. But its actually the "First Thing" of this nature.
- assuming that it can be provided without negative consequences for the current code base
All the current archives would have to be modified in some way to add this function and its default implementation.
or existing archive formats.
that would remain to be seen. Verifying this could be difficult. Robert Ramey