2

I am trying to make a Online C Compiler So multiple user can compile their code on a central server. And I can judge their code .

I want to calculate the time complexity ~ CPU Usages and the space complexity ~ Memory Usages of the C program. I am using Windows XP and cygwin gcc 4.5 compiler.

As a blog I am trying to take the memory usages of a process by pview

c:\cygwin\bin\gcc-3.exe -Wall source.c  -o a.exe 2>&1 | pv -o"%i\t%e\t%c2%%\t%m(K)\t%n" gcc-3.exe

It is return the memory usages by gcc-3 is 3520 KB in each cases either try to use 1000KB size or use no size i.e. simple printf statement.

Can you help me by the automate way to calculate the memory usage or space complexity of the program this is not necessary to use the above code It is only I am trying.

Suggestion and Answers are welcomed

Coren
  • 5,517
  • 1
  • 21
  • 34
Code Breaker
  • 499
  • 1
  • 4
  • 19
  • 1
    Are you interested in the program's memory consumption, or the compiler's? If you want to test the program, you should start by running it. – ugoren Mar 05 '12 at 12:50
  • @ugoren If I calculate the program's memory consumption then it is good for me but it is too hard so I am trying to calculate the compiler's memory consumption and later on I will correlate the program's space usages to the compiler usages. Can some one help help me to get the solution? – Code Breaker Mar 05 '12 at 13:02
  • 2
    There is not necessarily any correlation between the compiler's memory use and the final program's. – Fred Foo Mar 05 '12 at 13:19
  • 2
    As @larsmans says, there will likely be no correlation. A program can that does `malloc(100000000)` or defines `int x[100000000]` won't cause the compiler to consume more memory than `malloc(1)` or `int x[1]`. – ugoren Mar 05 '12 at 14:02

2 Answers2

1

Please have a look at this thread (actually, a comment):

Practically this is all what you have --- Using ulimit (on Unix) or Job Object (on Windows) to cap the memory consumption of your compiler. Predicting the memory consumption of your compiler beforehand for a given input source is, as @Yavar wrote, beyond our technology.

Btw why did you choose Cygwin on Win XP? That combination is so notorious for being difficult to handle. People usually use it in a last resort to port a software with Unix origin to Windows. I hope you won't make a exploitable security hole in your "online compiler" system...

Community
  • 1
  • 1
nodakai
  • 7,773
  • 3
  • 30
  • 60
1

Under Cygwin, I guess you can use getrusage. It contains many information about memory usage. This question gives more info about how it works and a practical example.

For windows only program, you have GetProcessMemoryInfo. See this question for more info about how it works.

Community
  • 1
  • 1
Coren
  • 5,517
  • 1
  • 21
  • 34