Thread: How do the global and local variables use the RAM?

  1. #1
    Registered User
    Join Date
    Sep 2011

    How do the global and local variables use the RAM?

    Hello all:

    Days ago I posted “How does the RAM work in C++ computing?” This post is
    “ How do the global and local variables use the RAM” They are sister questions.

    In C++, if a variable is defined outside a function, it is global variable,
    e.g. “float glbl[100][500]”. Alternatively Inside a function, it is a local variable ,
    e.g. “float lcl[100][500]”

    Do they have the same right/passibility to use the RAM?

  2. #2
    Join Date
    Oct 2007
    Inside my computer
    No. How they end up in RAM is up to the OS.
    In C++, all we know is that they are local, static or global. They have different semantics and limitations.
    Make no mistake, they all have to end up in RAM somewhere, but how and where? That is a specific question the operating system must answer.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    segmentation fault
    Elysia is correct that how memory segmentation is handled is not part of the C or C++ standard. It is determined by the OS, but the OS works according to some conventions determined by how the processor works.

    It's probably safe to say that 99.9%+ of contemporary operating systems on common architectures place local variables in the stack segment. Most of them probably also place globals in the data segment.

    Memory segmentation - Wikipedia, the free encyclopedia

    Any variable has "the right" to use the RAM it has been assigned, but as your last thread might indicate, no variable has the a right to be assigned any memory at all, and if it is not, using it can cause a problem.

    If you understand the limitations and set your expectations accordingly, it is not hard to get what you want.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. List local and global variables
    By saman in forum Tech Board
    Replies: 3
    Last Post: 06-03-2011, 12:04 PM
  2. Local vs Global Variables
    By BENCHMARKMAN in forum C++ Programming
    Replies: 5
    Last Post: 07-03-2007, 05:17 AM
  3. local and global variables???
    By geo_c in forum C Programming
    Replies: 5
    Last Post: 08-23-2004, 03:02 PM
  4. Global Vs Local Variables
    By Waldo2k2 in forum C++ Programming
    Replies: 17
    Last Post: 11-11-2002, 07:51 PM
  5. global and local variables
    By Unregistered in forum C++ Programming
    Replies: 2
    Last Post: 10-02-2001, 01:17 PM