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 7069367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:26:13+00:00 2026-05-28T05:26:13+00:00

what does something like this do? static int i; // wrapped in a big

  • 0

what does something like this do?

static int i;

// wrapped in a big loop
void update_text()
{
    std::stringstream ss; // this gets called again and again
    ++i;
    ss << i;
    text = new_text(ss.str()); // text and new_text are defined elsewhere
    show_text(text); // so is this
}

does is create a new instance of ss in the stack with a new address and everything? would it be smarter to use sprintf with a char array?

  • 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-05-28T05:26:14+00:00Added an answer on May 28, 2026 at 5:26 am

    Each time the function is called, a new, local, instance of std::stringstream ss is pushed upon on the stack. At the end of the function, this instance is destroyed and popped off the stack.

    At no point in time does the scope of function update_text have multiple variables in its scope with the identifier ss. So, within the scope of update_text, there is only one ss identifier.

    A character array would make no difference. Each time the function is called, the char array, if statically allocated, will be pushed onto the stack and popped off at the end. If you use dynamic memory and dynamically allocate the character array, the new and delete statements would still be executed each time the function was called, and the pointer to this character array would still be pushed and popped off the stack. The std::stringstream is already handling the new and delete for you internally.

    Declaring an object multiple times would look like this:

    void Function()
    {
        int x;
        int x;
    }
    

    This would cause compiler errors.

    Be warned, this however, is valid:

    void Function()
    {
        int x;
        if(true)
        {
            int x;
        }
    }
    

    Because the two variables are of different scopes. The second x exists only within that if statement. As such, the compiler can infer that any reference to x after that declaration and within that scope refers to the second x. Note that the type doesn’t matter, it’s the identifier or “name” that matters.

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

Sidebar

Related Questions

I have an auto-generated file which looks something like this... static void do_SomeFunc1(void* parameter)
Does something like this affect performance badly? var myQuery = from c in Customers
Does something like this make any sense at all in Java? class A<T extends
I am trying to optimize a query that does something like this: SELECT ...
I am working on a Bash shell script that does something like this: #!/bin/bash
I have a Visual Studio 2008 C++ application that does something like this: template<
does anyone know if you can do something like this using the (N)Hibernate criteria
I'm trying something like this, but this example does not work. jsObj = {};
What does this mean exactly? I'm doing something like this: File.Copy(@\\foo\bar\baz.txt, @c:\test\baz.txt); MSDN doesn't
This is a C# console application. I have a function that does something like

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.