c++ program using too much memory -
i have c++ program makes simulation. simulation large. needs ran several times.
i didn't take account memory management guidelines passing arguments reference functions avoid copies of same data wasting memory, , maybe other techniques don't know about. late redo whole program again (or maybe won't help).
i have program
void main(){ //simulation consuming lot of memory. };
i
void main(){ (int i=0;i<10000;i++){ //simulation consuming lot of memory (depending on i). }; };
but in such way after each loop of for memory used inside released (probably except used program , counter of for).
the memory holds fine 1 repetition of loop not two.
i there way can done?
on unix/linux, create bash shell script call c++ program required number of times, run_my_app.sh
following content:
i=0 while (( $i < 10000 )); ./my_app $i let i+=1 done
then make executable chmod +x run_my_app.sh
.
on windows, same cmd.exe
"shell", creating run_my_app.bat
with:
for /l %i in (0,1,9999) my_app %i
you can add full path my_app if need to, e.g.: c:\dir1\dir2\my_app
instead of my_app
. don't need make executable - that's implied .bat
extension.
then modify c++ program follows:
#include <cstdlib> int main(int argc, const char* argv[]) { if (argc != 2) { std::cerr << "usage: " << argv[0] << " i\n" "run simulation iteration number <i>.\n"; exit(exit_failure); } int = std::atoi(argv[1]); ...simulation... }
Comments
Post a Comment