programing

Discussion in 'C++' started by mc110403106@gmail.com, Jan 13, 2013.

  1. Guest

    #include <iostream.h>
    main()
    {
    long z,i,b;
    cin >> z;
    cout << z;
    for (i=0;i<z;i++)
    {
    for (int c=0;c<z;c++ )
    {
    long ac;
    /*sir i want here to create variable type long (ac)again and again
    ,a1,a2,a3..... but only one address variable created i wana see how
    much memoryy decrease with thousands of long variable*/

    cout << "p" << '\n' << &ac;
    }

    }

    }
     
    , Jan 13, 2013
    #1
    1. Advertising

  2. On 1/13/2013 6:10 AM, Juha Nieminen wrote:
    > wrote:
    >> long ac;
    >> /*sir i want here to create variable type long (ac)again and again
    >> ,a1,a2,a3..... but only one address variable created i wana see how
    >> much memoryy decrease with thousands of long variable*/

    >
    > And why, exactly?


    To verify an assumption, perhaps.

    > If you just declare a variable but never use, there's a good chance that
    > the compiler will optimize it away, so it will not take any memory.


    If it's a member of a class, or an element of an array, this will not
    hold necessarily.

    > And even if it did, why do it the hard way? The amount of bytes that a
    > variable of type 'long' takes is "sizeof(long)". Just multiply that by
    > the amount of variables, and you get how much memory they require
    > (assuming that they are actually used for something.)


    It's a funny thing, memory, isn't it? You allocate an array of five
    thousand longs, *and* write code to use it, and suddenly the process
    memory grows by more than 5000*sizeof(long). Is it linear? Is it
    logarithmic?... Somebody might want to find the pattern, *assuming*
    there is one. And then they might want to try to figure out the
    reason... They fancy themselves a researcher, so let them. Perhaps
    it's in vain to try to tell them not to do it because there is some
    theoretical dependency between the number of longs allocated and the
    amount of memory used. So? They probably want empirical evidence.

    V
    --
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Jan 13, 2013
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. valli

    structural programing

    valli, Nov 15, 2004, in forum: VHDL
    Replies:
    2
    Views:
    2,216
    Jim Lewis
    Nov 15, 2004
  2. Support

    Simple asp.net programing question

    Support, Jan 27, 2006, in forum: ASP .Net
    Replies:
    5
    Views:
    1,432
    Karl Seguin [MVP]
    Jan 27, 2006
  3. Murray J

    Some Programing Required

    Murray J, Dec 18, 2004, in forum: Java
    Replies:
    5
    Views:
    330
  4. chandu
    Replies:
    3
    Views:
    415
    Matt Humphrey
    Mar 2, 2006
  5. yuyazhang
    Replies:
    14
    Views:
    741
    yuyazhang
    Apr 29, 2006
Loading...

Share This Page