Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
到目前为止,我如何获得当前分配的总内存(在 Linux 进程中C/C++ (gcc))?
C/C++ (gcc)
尝试解析/proc/self/maps或/proc/$PID/maps. 查找标记为 的行[heap]。
/proc/self/maps
/proc/$PID/maps
[heap]
我喜欢 Rob 的回答,但这里有一个可能的选择。如果你能负担得起运行时的成本,你可以使用 valgrind 和massif工具。