public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* c++/4185: non functionality of string member (reserve)
@ 2001-08-31  6:36 colin
  0 siblings, 0 replies; only message in thread
From: colin @ 2001-08-31  6:36 UTC (permalink / raw)
  To: gcc-gnats

>Number:         4185
>Category:       c++
>Synopsis:       non functionality of string member (reserve)
>Confidential:   no
>Severity:       critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Aug 31 06:36:00 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Colin Thomas
>Release:        gcc version 2.95.2 19991024 (release) AND gcc version egcs-2.91.66 19990314/Linux
>Organization:
>Environment:
Solarirs 2.6 & linux
>Description:
I need to reduce memory usage in a large program.
Most of my C++ strings are just 1 or 2 characters in length,
but the default capacity is 16. I therefore want to use 
the reserve() string member function.

The reserve() member function works for vector container, but 
not strings (no affect).

I am unable to run on gcc3.0 as I use gtk+, and a bug was posted
on the gtk+ site to say not to migrate yet. 

>How-To-Repeat:
Run the small g++ example:

===================================
/////////////////////////////////////////////////////////////////
// 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 ;
}


===================================
>Fix:
If a workaround is known I would like to be informed.

Many thanks

/colin.
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/octet-stream; name="gccbug.cpp"
Content-Transfer-Encoding: base64
Content-Dispos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ycmVjdAogLy9UaGlzIGlzIHRoZSBkZWZhdWx0IHZhbHVlIGFzIGlmIHJl
c2VydmUgaGFzIG5vdCBiZWVuIHJ1bi4KIGNvdXQgPDwgVGhpc1N0cmluZy5jYXBhY2l0eSgpIDw8
IGVuZGwgOwp9Cg==


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2001-08-31  6:36 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-08-31  6:36 c++/4185: non functionality of string member (reserve) colin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).