basic_stringbuf<>::sync

Ryszard Kabatek rysio@rumcajs.chemie.uni-halle.de
Tue Jun 1 12:43:00 GMT 1999


basic_stringbuf<>::sync calls the non-const version of the
basic_string<>::begin and basic_string<>::end member function. 
It makes the _M_str object unsharable.
So any call of setbuf (it calls sync) requires a reallocation.

A possibly solution is to call a const member function and use 
the const_cast operator to remove the const modifier:

      virtual int 
      sync()
      {
        char_type __first = const_cast<char_type>(_M_str.data()); 
        char_type  __last = const_cast<char_type>(_M_str.data() +
                                                  _M_str.size());

        if (_M_mode & ios_base::in)
          setg(__first, __first, __last);
        if (_M_mode & ios_base::out)
          setp(__first, __last);
        return 0;
      }


Ryszard Kabatek
Martin-Luther University Halle-Wittenberg, Department of Physical Chemistry
Geusaer Str. 88, 06217 Merseburg, Germany
Tel. +49 3461 46 2487 (2466) Fax. +49 3461 46 2129



More information about the Libstdc++ mailing list