Thomas McGuire wrote:
> 
> Hi,
> 
> Writing or reading a std::vector<std::string> to DataOStream or from 
> DataIStream will lead to corrupted memory and hard to track down bugs.
> This is because the specializations of operator << and >> for std::vector
> do 
> things like
> write( &value[0], nElems * sizeof( T ) ); and
> read( &value[0], nElems * sizeof( T ) );
> 
> This will bypass the constructor & copy constructor of std::string, which
> is 
> not good.
> 
> Therefore, I propose to change the operators to do the following:
> 
> operator <<:
> {
>     const uint64_t nElems = value.size();
>     write( &nElems, sizeof( nElems ));
>     for ( int i = 0; i < nElems; i++ )
>     {
>         (*this) << value[i];
>     }
>     return *this;
> }
> 
> operator >>:
> {
>     uint64_t nElems = 0;
>     read( &nElems, sizeof( nElems ));
>     value.resize( nElems );
>     for ( int i = 0; i < nElems; i++ )
>     {
>         (*this) >> value[i];
>     }
>     return *this;
> }
> 
> This fixes the problem.
> 
> Regards,
> Thomas
> 
> 

Hi,

i think my problem belong to this thema so i post it here. i hope this is
not too bad. : )
i have a relativ big vector to send (1366875 elements), so it cost much time
in the for-loop(perhaps). when i used the read & write methods i got the
problem as Thomas mentioned. i don't know how to get rid of it & need help. 

thanks a lot in advance

Bo Lou 
-- 
View this message in context: 
http://n2.nabble.com/Bug-in-DataIStream%3A%3Aoperator-%3E%3E-and-DataOStream%3A%3Aoperator-%3C%3C-tp2290241p2973405.html
Sent from the Equalizer - Parallel Rendering mailing list archive at Nabble.com.


_______________________________________________
eq-dev mailing list
[email protected]
http://www.equalizergraphics.com/cgi-bin/mailman/listinfo/eq-dev
http://www.equalizergraphics.com

Reply via email to