Thread: creating C programs to test memory usage

  1. #1
    Registered User
    Join Date
    Oct 2009

    creating C programs to test memory usage

    I've been tasked with creating programs to test a new systems performance. Amongs these programs are programs that test memory usage. I need
    1) a program that allocates increasingly large memory from the heap
    2) A series of programs that have 'a large runtime memory image'

    The first was apparently easy to do, just malloc increasingly larger memory sizes. However, when I do that and check the system memory it doesn't seem to change. There is some variation, but it doesn't seem remotely consistent with what my program is doing, presumably the variation is due to memory being used by other programs in the background. Is there a reason that mallocing large portion of memory in my C++ app wouldn't show on system resources?

    The second requirement isn't obvious to me. Short of creating a program with 10000 for loops in it I can't think of a way to make the programs run time image is as large as needed.

    It's been awhile since I touched C, I've been in Java land the last few years. In fact my C++ knowledge is sadly limited, so it's possible I'm missing something obvious here. Any help would be appreciated

    Thank you

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Well it rather depends on your OS.

    In Linux for example, simply mallocing a megabyte doesn't immediately cause 1MB to be mapped to your address space. You need to touch the memory to cause that to happen.

    Further, at some point you're going to start swapping memory - sometime before the amount of REAL memory is reached, and almost certainly before the amount of virtual memory (per process) is reached.

    > 2) A series of programs that have 'a large runtime memory image'
    A naive flood fill eats memory!
    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. Dynamic Linking & Memory usage
    By @nthony in forum C Programming
    Replies: 2
    Last Post: 06-02-2007, 09:57 PM
  2. Deleting objects show no drop in memory usage.
    By theJ89 in forum C++ Programming
    Replies: 8
    Last Post: 04-02-2006, 06:21 AM
  3. Pointer's
    By xlordt in forum C Programming
    Replies: 13
    Last Post: 10-14-2003, 02:15 PM
  4. Accessing memory of other programs
    By Inquirer in forum C Programming
    Replies: 4
    Last Post: 10-07-2003, 03:43 PM
  5. Is it necessary to write a specific memory manager ?
    By Morglum in forum Game Programming
    Replies: 18
    Last Post: 07-01-2002, 01:41 PM