1 / 6
Feb 2010

Hi, I am trying to build some sort of judge program (in C), which can judge files locally, but the problem is about memory limit.
For example, I may want a program to run under 32MB memory, while another one under 8MB. So is there any option in C/C++ compiler parameter to limit the stack size / available memory (I use gcc / g++ under Linux, Ubuntu 9.10) or any shell scripts available to be used before invoking gcc / g++ ? I have tried to look for it in internet, but perhaps I looked the wrong way.

So, it would be a great help if I could get any clue from anyone here. Thanks in advance smile

  • created

    Feb '10
  • last reply

    Mar '10
  • 5

    replies

  • 860

    views

  • 4

    users

I may have a solution but you will have to try it out. You can use the command :

ulimit -v (maximum memory limit)

This limits the virtual memory that can be allotted to a process. To restore it back just use :

ulimit -v unlimited

Hope it helps smile

11 days later

I am unable to allocate more than 2.4G of memory for a C++ program though I have approximately 4G of physical memory and I am using g++ on a RH9 box.

Was there a question there?

If you're trying to use the rest of that memory, then it's likely the operating system limiting you in some way. G++ just compiles your code into instructions that the machine can use.

If you're working on a spoj problem, then you might as well stop and rethink your method, as you won't get it to run here either.

If that was just a statement and you didn't forget to ask the question... That's nice.

A little bit of Google-fu leads me to believe that the maximum amount of memory that redhat can use is dependent on the kernel and it's instructions, you might want to read your documentation.

Unless of course you still weren't actually asking a question.