Topic: basic_string.reserve(0) meaning
Author: Valentin Bonnard <bonnardv@pratique.fr>
Date: 1998/11/24 Raw View
Howard Hinnant wrote:
>
> In article <199811231632.RAA03513@su5bpc.labogeo>,
> Philippe.Couton@sercel.fr (Philippe COUTON) wrote:
>
> > The CD2 Draft describes in section 21.3.3 the basic_string's member function
> > reserve() as follows:
> >
> > void reserve(size_type res_arg=0);
> >
> > But what is the meaning of the 0 default value for the res_arg argument? What
> > is the significance of telling to a basic_string object than I plan to use a
> > size of 0? I don't see.
>
> This is a "non-binding shrink-to-fit request".
BTW it can't be binding because you can't determine if you
already have the minimum capacity; even if size() < capacity(),
the few remaining bytes might not be available for other
allocations (esp if size() doesn't divide 2/4/8).
--
Valentin Bonnard mailto:bonnardv@pratique.fr
info about C++/a propos du C++: http://pages.pratique.fr/~bonnardv/
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: Philippe.Couton@sercel.fr (Philippe COUTON)
Date: 1998/11/23 Raw View
The CD2 Draft describes in section 21.3.3 the basic_string's member function
reserve() as follows:
void reserve(size_type res_arg=0);
The member function reserve() is a directive that informs a basic_string
object of a planned change in size, so that it can manage the storage
allocation accordingly. Effects:
I understand that as a hint saying to a basic_string object that I will need
soon a size of at least res_arg.
But what is the meaning of the 0 default value for the res_arg argument? What
is the significance of telling to a basic_string object than I plan to use a
size of 0? I don't see.
If I have a basic_string object s with a size of 20 for example, what is his
state after executing s.reserve()?
Regards,
Philippe Couton
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: hinnant@_anti-spam_lightlink.com (Howard Hinnant)
Date: 1998/11/24 Raw View
In article <199811231632.RAA03513@su5bpc.labogeo>,
Philippe.Couton@sercel.fr (Philippe COUTON) wrote:
> The CD2 Draft describes in section 21.3.3 the basic_string's member function
> reserve() as follows:
>
> void reserve(size_type res_arg=0);
>
> But what is the meaning of the 0 default value for the res_arg argument? What
> is the significance of telling to a basic_string object than I plan to use a
> size of 0? I don't see.
This is a "non-binding shrink-to-fit request".
This wording was introduced after the CD2.
> If I have a basic_string object s with a size of 20 for example, what is his
> state after executing s.reserve()?
Depending on the implementation, it may do nothing, or it may knock your
capacity down to 20 (if it was higher).
-Howard
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]