hi all,
i wanted to know(just for curiosity) can we write any code which gives us the memory ocupied by any other c-program.so that if we have two different codes written for the same algo ,we can compare which one is better memory wise.
thanks.
hi all,
i wanted to know(just for curiosity) can we write any code which gives us the memory ocupied by any other c-program.so that if we have two different codes written for the same algo ,we can compare which one is better memory wise.
thanks.
Well that all depends on your OS and compiler.
Generally, "yes" is the answer, but there's no set method.
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.
You should just run the algorithm in a program that keeps track of how many bytes of memory it allocates. Much easier doing it from the inside out than the outside in, especially considering your programs can't access the memory of another program directly.
"What's up, Doc?"
"'Up' is a relative concept. It has no intrinsic value."
A great deal here would depend on what granularity of precision you need. Windows Task manager and Linux/Unix ps or top will show you memory usage, but it's not showing a great deal of precision, so if you need to know EXACTLY (or within a few dozen bytes or so), then you would, as IceDane suggests, have a "hacked" version of malloc/free and/or new/delete (and their collegues) to track memory usage.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
matsp,can u plz tell me how can i see memory usage using task manager.i'm using windows xp and turbo c++.also what do u mean by "hacked" version of malloc/free.
In task manager, in the tab called "Processes", you'd see a column saying "Mem Usage". If you don't, make the window wider. If that's not showing it, try View->Select Columns and select "Memory usage". You may also want to use "Peak memory usage".
As to hacked malloc/free, I mean that you use methods that replace the malloc and free with your own versions, that track the amount of memory used (a macro replacement that translates "malloc" to "mymalloc", etc. is the simplest form).
Also, if you use Turbo C as a DOS executable, then you probably won't see which uses the most memory, because of the way that DOS deals with free memory. There may be a function in Turbo C libraries to "get amount of free memory" - I remember Turbo Pascal had such a feature.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.