Thread: intentially create program with large run-time memory

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    4

    intentially create program with large run-time memory

    I'm working on a suit of tests to be run on a brand new high performance computer and trying to run some performance tests to see how well it manages forks, IO, memory usage ect.

    Anyways I want to create multiple programs, one that requires 1 MB to load into memory, and then a number of increasingly larger programs. I'm not trying to test the heap, already have a test for this, but the memory to load the program into the stack. The question is how do I do this? I see two problems

    1) I don't want to sit there putting 1000 no-ops (or C++ equivalents) in my code just to increase it's size, I'm assuming there is a quicker way to do this.
    2)I don't want the compiler to realize the program is needlessly complex and optimize it (although I assume that I can do that by simply not using the -02 argument?)

    Would just creating a program with a large int array that is never used and compiling it without the -02 flag do this?

  2. #2
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    Creating a large array would not increase the code size.

    The only thing I can think of is recursive templates:
    Code:
    normalFunc();//not inline!
    
    template <unsigned I>
    class Repeat{
    public:
      static void func()
      {
        normalFunc();
        func<I-1>();
      }
    }
    template <>
    class Repeat<0> {
    public:
      void func(){}
    }
    This is basically an unrolled loop. It will create I calls to normalFunc().

    Only problem is that Standard C++ only requires this to work for I<=7
    Last edited by King Mir; 10-30-2009 at 09:08 AM.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  3. #3
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    First, note that on modern VM operating systems, just because code is mapped into the address space doesn't necessarily mean it is actually loaded from disk and placed into memory. That normally only happens when the code is executed (i.e. the pages are required). So you may not actually be testing what you think you are testing.

    Having said that, recursive includes can get big quickly. Try:

    Code:
    /* base.h */
    for( i = 0; i < 100; ++i )
        total += i * total;
    
    ----------------
    
    /* recurse1.h */
    #include "base.h"
    #include "base.h"
    #include "base.h"
    #include "base.h"
    #include "base.h"
    #include "base.h"
    #include "base.h"
    #include "base.h"
    
    ----------------
    
    /* recurse2.h */
    #include "recurse1.h"
    #include "recurse1.h"
    #include "recurse1.h"
    #include "recurse1.h"
    #include "recurse1.h"
    #include "recurse1.h"
    #include "recurse1.h"
    #include "recurse1.h"
    
    ----------------
    
    /* recurse3.h */
    
    #include "recurse2.h"
    #include "recurse2.h"
    #include "recurse2.h"
    #include "recurse2.h"
    #include "recurse2.h"
    #include "recurse2.h"
    #include "recurse2.h"
    #include "recurse2.h"
    
    ----------------
    
    /* recurse4.h */
    
    #include "recurse3.h"
    #include "recurse3.h"
    #include "recurse3.h"
    #include "recurse3.h"
    #include "recurse3.h"
    #include "recurse3.h"
    #include "recurse3.h"
    #include "recurse3.h"
    Including recurse4.h now creates 4096 copies of the code in base.h. You can add more includes at each level, or add more levels, to get huge volumes of code.

    Note that the code in base.h depends on some variables that need to be declared somewhere else.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  4. #4
    Registered User
    Join Date
    Oct 2009
    Posts
    4
    a belated thank you for the responce. I think the recursive imports should work. I'll try them now

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. c program that accepts and executes commands?
    By Cimposter in forum C Programming
    Replies: 3
    Last Post: 09-30-2009, 02:58 PM
  2. How program run predefine time?
    By Arafat_211184 in forum C Programming
    Replies: 9
    Last Post: 12-16-2005, 03:44 AM
  3. Locating A Segmentation Fault
    By Stack Overflow in forum C Programming
    Replies: 12
    Last Post: 12-14-2004, 01:33 PM
  4. Trying to make rand different per program run
    By Dreamerv3 in forum C++ Programming
    Replies: 6
    Last Post: 01-18-2002, 03:26 AM