Re: [ROOT] Performance of Streamers -- code generated for STL vectors.

From: Walter F.J. Mueller (W.F.J.Mueller@gsi.de)
Date: Mon Dec 03 2001 - 16:12:25 MET


Aaron Dominguez wrote:
> Instead of the for() loop for reading/writing the std::vector, I've been using
> ReadFastArray/WriteFastArray, like so:
> 
> if (R__b.IsReading()) {
>    int n;
>    R__b >> n;
>    fCoeff.resize(n);
>    R__b.ReadFastArray(&fCoeff[0],n);
> }
> else {
>    R__b.WriteVersion(MyClass::IsA());
>    R__b << fCoeff.size();
>    R__b.WriteFastArray(&fCoeff[0],fCoeff.size());
> }
> 
> I'm pretty sure that this is ok since I believe that std::vectors are supposed
> to be contiguous in memory from beginning to end.  At least this is working
> for us at CDF with ROOT v3.01/06a, KCC v4.0f or gcc v3.  And we've always had
> great success speeding up streamers with Read/WriteFastArray.

I'm doing just the same, and it speeds up quite a bit. To the best of my
knowledge did the original STL specification not guarantee that the elements
of a vetor are stored in contiguous memory. However, all implementations I've
seen do this, and afaik it is dicussed to explicitely require this in the
future. But one has to keep in mind that this only applies to vector, but
not for example for deque.

So even though it is not covered by the current STL specification one can in
practice use ReadFastArray/WriteFastArray when the container is vector and
the type one of the integer and float types supported by ReadFastArray. For
all other typpes it still helps to use reserve(). For all other containers
the current style of Streamers is fine.


			Cheers,	Walter

--
Walter F.J. Mueller   Mail:  W.F.J.Mueller@gsi.de
GSI,  Abteilung KP3   Phone: +49-6159-71-2766
D-64291 Darmstadt     FAX:   +49-6159-71-2989
WWW:   http://www-kp3.gsi.de/www/kp3/people/mueller.html



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:51:10 MET