This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

string reserve()


Hi,

I have a program that deals with small strings - 1-2 characters. The default
capacity() is getting set to 16 (and wasting memory)

I have tried the following on my 2.95.2 version of gcc

######################################
/////////////////////////////////////////////////////////////////
// STL Class Templates
#include <iostream>
#include <vector>
#include <iomanip>
#include <string>

using namespace std ;

///////////////////////////////
void main()
{
 //Define a vector string
 vector<string> v;
 //define a C++ string
 string ThisString ;
 ThisString = "A";
 //set the capacity of the string to 1000
 ThisString.reserve(1000);
 //Set the capavity of the vector to 1000
 v.reserve(1000);

 //v.size reports back 0 == correct
 cout << v.size() << endl ;
 //v.capacity reports back 1000 == correct
 cout << v.capacity() << endl ;
 //ThisString.size() reports back 1 == correct
 cout << ThisString.size() << endl ;
 //ThisString.capacity() reports back 16 NOT 1000 ==> NOT correct
 //This is the default value as if reserve has not been run.
 cout << ThisString.capacity() << endl ;
}
######################################


The reserve() on a string does not seem to have any affect ;-(
(while it seems to work okay on vector<string>

Firstly, has anyone seen this before ??

Secondly, how do I know what version of libstdc++ I have got installed - 
I have libstdc++.so.2.10.0 , but the numbering does not link in with
anything like libstdc++-2.92 ?

I hear rumours pertaining to gcc3.0 having libstd auotmatically included
(so I just need one installation not two) - is this correct ? Will gcc3.0+
fix the above, and how stable is it (I use gtk+ and they are reporting 
some issues).

I hope you can put be back on the staright and narrow ;-)

best regards

/colin.





Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]