Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8713061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:15:15+00:00 2026-06-13T05:15:15+00:00

I got that sample source: std::string tmp1; std::string tmp2 = Test; while(1) { tmp1

  • 0

I got that sample source:

std::string tmp1;
std::string tmp2 = "Test";


while(1)
{
    tmp1 += tmp2;
}

We see that tmp1 gets the content of tmp2 and each loop it adds “Test” at the end of the string. I know that this should be similar to strcat(), but strcat is a C function and it has got C function realloc()

How do std::string implements concatenation of strings?
Does it use some kind of reallocation of memory? If yes how do I reallocate in C++?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T05:15:16+00:00Added an answer on June 13, 2026 at 5:15 am

    First off, strcat() doesn’t allocate any memory! If you provide a too small buffer to strcat() you’ll get a buffer overrun, not a reallocation.

    The std::string class internally manages memory. It will reallocate memory using a suitable sequence of using new and delete operators. The way it is specified it will overallocate memory and not allocate new memory on each string addition.

    If you need to use variable sized amounts of memory, you are probably best off to use std::vector<T> for a suitable type T. This class takes care of allocating and releasing memory. You just tell it how many elements you need. Under the hood it is also using combinations of new and delete operators (well, actually an allocator object) to maintain memory. There is no direct support for something like C’s realloc().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a source code file that started as a copy of some sample
I've got a piece of text that contains another regular expression. Sample text: ...<rege>!^.*$!mailto:asdf@adsfsdaf.com!</rege>...
I've got a fairly simple loop that supposed to run through all elements in
Assume I have a sample source file, test.c, which I am compiling like so:
I've just tried running the sample java files that I got with the epson
I've got a JSON string that I want to convert to a Map structure
To have an indicator while doing an ajax request, I got information saying that
I've got a site http://abc.com/support , which uses an iFrame that has a source
I got some sample code from the net here: http://www.javadb.com/sending-a-post-request-with-parameters-from-a-java-class That works fine. It
I've got a site that's relatively simple. The user performs some action on the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.