public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: colin@designresources.co.uk
To: gcc-gnats@gcc.gnu.org
Subject: c++/4185: non functionality of string member (reserve)
Date: Fri, 31 Aug 2001 06:36:00 -0000	[thread overview]
Message-ID: <20010831133217.16746.qmail@sourceware.cygnus.com> (raw)

>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="g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rIDE2IE5PVCAx
MDAwID09PiBOT1QgY29ycmVjdAogLy9UaGlzIGlzIHRoZSBkZWZhdWx0IHZhbHVlIGFzIGlmIHJl
c2VydmUgaGFzIG5vdCBiZWVuIHJ1bi4KIGNvdXQgPDwgVGhpc1N0cmluZy5jYXBhY2l0eSgpIDw8
IGVuZGwgOwp9Cg==


                 reply	other threads:[~2001-08-31  6:36 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20010831133217.16746.qmail@sourceware.cygnus.com \
    --to=colin@designresources.co.uk \
    --cc=gcc-gnats@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).