public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: martin@v.loewis.de
To: gcc-gnats@gcc.gnu.org
Subject: libstdc++/4960: std::string slow to append individual characters
Date: Wed, 21 Nov 2001 12:36:00 -0000	[thread overview]
Message-ID: <200111272301.fARN1Kb02682@mira.informatik.hu-berlin.de> (raw)


>Number:         4960
>Category:       libstdc++
>Synopsis:       std::string slow to append individual characters
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Tue Nov 27 15:06:00 PST 2001
>Closed-Date:
>Last-Modified:
>Originator:     Martin v. Loewis
>Release:        3.1 20010813 (experimental)
>Organization:
HUB
>Environment:
System: Linux mira 2.4.10-4GB #1 Tue Sep 25 12:33:54 GMT 2001 i686 unknown
Architecture: i686

	
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: /usr/src/egcs/configure --prefix=/usr/local/newabi --enable-shared --enable-threads --enable-languages=c,c++,java
>Description:
In gcc 2.95, adding one character after another to an std::string resulted in infrequent
memory allocations, as the implementation would reserve sufficient memory. In libstdc++ v3,
each append invocation will cause reallocation (and copying of the existing string) once
the reserve is exhausted.
>How-To-Repeat:
Compile and benchmark the following program with both gcc 2.95 and gcc 3 on the same machine.
On a 900MHz Pentium III, the 2.95 compilation result needs 0.01s, the gcc 3 result needs 4.0s.

#include <string>
#include <stdio.h>

int main()
{
	std::string s;
	int i;
	for(i=0;i<100000;i++){
		//printf("%d %d\n",i,s.capacity());
		s+=" ";
	}
}
>Fix:
	Add a reserve larger than the current size in std::string::append.
        The strategy of libstdc++ 2 (using the nearest power of 2) seems reasonable.
>Release-Note:
>Audit-Trail:
>Unformatted:


             reply	other threads:[~2001-11-27 23:06 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-11-21 12:36 martin [this message]
2001-11-21 13:16 pme
2001-11-21 14:36 pme
2001-12-05  0:40 paolo
2001-12-05  0:46 paolo
2001-12-08  1:52 paolo
2001-12-08  1:56 paolo

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=200111272301.fARN1Kb02682@mira.informatik.hu-berlin.de \
    --to=martin@v.loewis.de \
    --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).