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

  • Home
  • SEARCH
  • 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 8439949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:08:56+00:00 2026-06-10T08:08:56+00:00

I want to understand exactly where the global variables are stored in my program.

  • 0

I want to understand exactly where the global variables are stored in my program. On the stack? On the heap? Somewhere else?

So for that I wrote this small code:

int global_vector[1000000];
int main () {
    global_vector[0] = 1; // just to avoid a compilation warning
    while(true); // to give me time to check the amount of RAM used by my program
    return 0;
}

No matter how large I make global_vector, the program only uses a really tiny amount of RAM. I do not understand the reason for this. Could someone please explain?

  • 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-10T08:08:57+00:00Added an answer on June 10, 2026 at 8:08 am

    This is completely implementation-dependent, but typically global variables are stored in a special memory segment that is separate from the stack and the heap. This memory could be allocated as a fixed-size buffer inside of the executable itself, or in a segment that is given to the program at startup by the operating system.

    The reason that you’re not seeing the memory usage go up probably has to do with how virtual memory is handled by the OS. As an optimization, the operating system won’t actually give any memory to the program for that giant array unless you actually use it. Try changing your program to for-loop over the entire contents of the array and see if that causes the RAM usage to go up. (It’s also possible that the optimizer in your compiler is eliminating the giant array, since it’s almost completely unused. Putting a loop to read/write all the values might also force the compiler to keep it).

    Hope this helps!

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

Sidebar

Related Questions

I want to understand how a C++ program that was given to me works,
I want to understand exactly which part of a program compiler looks at and
I want to understand why the following is happening. My guess is that a
I want to understand exactly what unit test means. From what I have understood
Possible Duplicate: Learning about LINQ Hi everyone, I just want to understand what exactly
I was wondering if this was possible. Mostly I want to understand what GNOME
I don't exactly understand how ASP.NETs ActionLinks work. I see that they have a
I am new to Struts2 and would want to understand how exactly does it
I am trying to understand exactly what is going on with this method, as
I understand exactly why unused variable warnings occur. I don't want to suppress them

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.