Aug 16, 2016 at 7:13pm UTC
Here is my code :
#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
for(int n = 0;n <= 500000;n+=4) // from 0 to 500000 4 bytes
{
system("cls");
cout << n << hex << endl; // print memory addres of n(int)
}
system("cls");
cout << "finish" << endl;
system("pause");
return 0;
}
When run program wait a long time to finish
Last edited on Aug 16, 2016 at 7:21pm UTC
Aug 16, 2016 at 7:43pm UTC
Not sure what you want the program to do.
You could make the program output "finish" much quicker by simply removing the loop.
Aug 16, 2016 at 8:13pm UTC
I wont to make memory address Search(like Cheat Engine) this is not full code but this take Long time to finish
Last edited on Aug 16, 2016 at 8:13pm UTC
Aug 16, 2016 at 8:30pm UTC
It will be faster when you remove system("cls" );
inside the for loop.
Aug 19, 2016 at 8:20pm UTC
system() runs a separate program. It has to find the program, allocate memory for it, load the program into the memory, run it, and then free up the memory. That's really expensive. If I reduce to loop count to 5,000, the program takes 22 seconds to run.
Changing
system("cls" )
to instead print out the escape sequence to clear the screen (ESC [2J) the runtime drops to 19ms.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#include <iostream>
#include <windows.h>
using namespace std;
int
main()
{
const char esc = 27;
for (int n = 0; n <= 5000; n += 4) // from 0 to 500000 4 bytes
{
// system("clear");
cout << esc << "[2J" ;
cout << n << hex << endl; // print memory addres of n(in\
t)
}
cout << esc << "[2J" ;
// system("clear");
cout << "finish" << endl;
return 0;
}
Last edited on Aug 19, 2016 at 8:21pm UTC