我该如何制作这个以便所有东西都可以使用它? C++
我对 C++ 有点陌生,所以我不知道如何做到这一点,但我重新编码的主要目的是提高程序的速度,我一直在编码一个项目 我的代码是:
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);
所以我有大约 20 个函数,它们在每次运行它们时都使用它们,并且值永远不会改变,所以有什么方法可以声明然后将其设置为它找到的值?
我的代码设置就像这样
一个主文件 int main() ,它只是设置在一个循环上,它不断重新测试并调用其他函数,其他所有内容都在 void name() 中,我有2 int name()
我使用 VC++ 2008。
编辑 不:|我只是想要一种可以与所有程序分享这些价值观的方法。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我正确理解你的问题,你想实现某种缓存。那很好,您可以使用
std::map
创建一个缓存。您可能会遇到类似的情况:
然后您可以检查
cacheMap
以查看结果是否存在。如果它确实存在,您不需要调用该函数,如果它不存在,您将调用该函数并将结果添加到您的地图
中。If I understand your question correctly you want to implement some kind of caching. That would be fine and you can create a cahe with an
std::map
.You would probably have something like:
You can then check the
cacheMap
to see if a result exists. It if does exist you don't need to call the function, if it does not exist you would then call the function and add the result to yourmap
.