1

im somewhat new to c++ so i don't know how to do this but my main point in recoding this is to incress the speed of my program, i have been coding a project and my code is:

HWND hWnd = FindWindow(NULL, L"*window's name*");
DWORD th32ProcId;
HANDLE hProc;

GetWindowThreadProcessId(hWnd, &th32ProcId);

hProc = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ, 0, th32ProcId);

so i have about 20 functions that all use that at the start of each time i run them and the value will never change so is there some way i can declare and then set it at the value of what it finds?

my code is set up like this

one main file int main() and it's just set on a loop and it keeps retesting and calls the other functions and everything else is in a void name() and i have 2 int name()

im using VC++ 2008.

edit no :| i just want a way i can share thoses values with all of the program.

4

1 回答 1

2

如果我正确理解您的问题,您想要实现某种缓存。那很好,您可以使用std::map.

你可能会有类似的东西:

std::map<std::string, HANDLE> cacheMap;

然后,您可以检查cacheMap以查看结果是否存在。如果确实存在,您不需要调用该函数,如果它不存在,您将调用该函数并将结果添加到您的map.

于 2010-02-22T01:44:15.313 回答