gpt4 book ai didi

c++ - 在 C++ 中获取总内存和可用内存

转载 作者:太空狗 更新时间:2023-10-29 21:46:08 27 4
gpt4 key购买 nike

C++有java中的方法吗

Runtime.getRuntime().totalMemory()
Runtime.getRuntime().freeMemory()

我是这样用的

long mem0 = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
/*
stuff to do
*/
long mem1 = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory();
System.out.println(mem1-mem0);

查找程序使用的内存。这里有 C++ 中的任何类似物吗?

最佳答案

C++标准中没有规定,Windows下需要使用WinAPI For example this在 Linux 下,您需要使用库或调用系统调用。

关于c++ - 在 C++ 中获取总内存和可用内存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15833740/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com