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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:59:32+00:00 2026-06-15T21:59:32+00:00

I wanted to know in each couple of loop code, whether some version consumes

  • 0

I wanted to know in each couple of loop code, whether some version consumes less memory than the second one, and if it’s true that in some versions we allocated new space for a variable in each loop cycle.

Note: 2 is pretty obvious, 1 and 3 are more interesting..

1.

While(!exit)
{
  int x = 5;
}

Versus:

int x= 0;
While(!exit)
{
  x = 5;
}

Same question for reference types:
2.

While(!exit)
{
      Point p = new Point();
      p.x = 5;
}

Versus:

Point p = new Point();
While(!exit)
{
      p.x = 5;
}

3. Reference type without allocation similar to 1?:

While(!exit)
{
      Point p = point1;
}

Versus:

Point p = null;
While(!exit)
{
   p = point1;
}
  • 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-15T21:59:33+00:00Added an answer on June 15, 2026 at 9:59 pm

    The compiler decides how many stack storage locations your function needs and will do what it can to reduce that need. Something like:

    {
       int a;
       ...
    }
    {
       int b;
       ...
    }
    

    Seems to require two storage locations, but the compiler can see that the first is never used outside the first scope and can re-use the location for b.

    It may also see that it can do away with the stack storage all together and perform the whole thing in registers.

    Whether looping or not, a single variable declaration defines a single storage location. It would never be the case that a new storage location would get created for each iteration of the loop.

    In general, this is not something you need to be concerned with.

    Note that “debug” builds might produce separate storage locations on the stack for every variable declared to make viewing those variables while debugging easier.

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

Sidebar

Related Questions

I wanted to know if I have to create a new ViewController for each
I wanted know how the kernel is providing memory for simple C program .
Wanted to know if there was a way one could query shelveset details from
Wanted to know if someone had a suggestion on code or maybe there's a
Just wanted to know that which one will be better: creating a different container
I'm attempting to condense several SQL calls into one, and wanted to know if
I wanted to know if there is any event which occurs each time a
I wanted to know how to process a list of LESS files using the
i wanted to know how to put two div right next each other centered
I just wanted to know if somebody knows some jQuery scripts that do some

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.