Thread: How does the RAM work in C++ computing?

  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    12

    How does the RAM work in C++ computing?

    Hello all:

    In my knowledge that the usefulness of RAM in computing is for storing data such as array. That’s why we need large RAM If the program is large. BUT recently I am confused.

    I have 2-PC, one old Toshiba Satellite and a new HP pavilion. Both re-installed with XP pro sp3. By “My Computer/ Properties /General” check them, the memory are: 1.00 GB of RAM and
    2.90 GB RAM.

    I have a stock program with large 2-dimension array, the 1st array for storing tickers and the 2nd for quotes. Because of large tickers and quotes, it’s sure that it requires large memory/RAM.

    Using VC++2008, II run this program in the old, RAM=1 GB, PC, it prompts the small grey/silver window, with ‘Debug’ ‘Send Error Report’ ‘Don’t Send’ three press button, meaning that RAM is not enough to store all the 2-dimension array/variables.

    I transferred to run it in the new, RAM=2.9 GB, PC. To my surprise the result is the same: appeared the gray/silver small window the same.

    I decrease the size of the 2-dimension variable/array, both PCs are OK.

    Repeated experiments showed: both PC have the same ability to store variable/array! CAN

    1.0 GB of RAM = 2.90 GB of RAM ???

    I am stunned! Could you helped me?

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Variables on the stack != RAM.

  3. #3
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    I took a Honda Civic and a Chevy Suburban and threw them off a cliff. They both shattered into little pieces. Amazingly, a Honda Civic seems to be indistinguishable from a Chevy Suburban. I am stunned.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  4. #4
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by YuminZhao View Post
    I have a stock program with large 2-dimension array, the 1st array for storing tickers and the 2nd for quotes. Because of large tickers and quotes, it’s sure that it requires large memory/RAM.
    Is the array on the heap or in the stack? I'm not a VC++ or MS user, so I dunno about your error popup, but if the array is on the stack, the size of the stack is predetermined by the compiler, it will be the same regardless of the total RAM, and it will be much less than a GB.

    Quick google reveals Visual Studio 2005 has a default stack size of 1 MB.

    /F (Set Stack Size) (C++)
    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

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    I second tabstop.

    > I decrease the size of the 2-dimension variable/array, both PCs are OK.
    > Repeated experiments showed: both PC have the same ability to store variable/array!
    I'm guessing you reduced the size of your array down to something in the region of say 1MB.

    Regardless of how much physical RAM the machine has, windows gives each process a virtual 1MB of stack space. Almost all of the rest (up to about 1/2 the virtual address space (approx 2GB) you can allocate using new(C++) or malloc(C)

    But you need to post actual code to get a proper answer.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. computing the sum within a loop
    By zesty in forum C Programming
    Replies: 1
    Last Post: 12-03-2009, 01:03 PM
  2. computing the GCD non-recursively
    By rrreeefff in forum C Programming
    Replies: 2
    Last Post: 10-05-2008, 10:57 PM
  3. computing median value
    By ademkiv in forum C Programming
    Replies: 3
    Last Post: 04-03-2006, 09:43 PM
  4. Computing Problem
    By Gsibbery in forum C Programming
    Replies: 6
    Last Post: 06-11-2003, 08:11 AM
  5. Quantum Computing..
    By vasanth in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 01-13-2003, 10:51 AM