在运行时,如何以编程方式确定动态链接库使用了多少内存? [英] At runtime, how can I determine programmatically how much memory is used by dynamically-linked libraries?

查看:43
本文介绍了在运行时,如何以编程方式确定动态链接库使用了多少内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道我的应用程序使用了多少内存.我还想知道我的程序的哪一部分使用的内存最多.例如,我有一个使用 100MB 内存的进程,该进程中有一个使用 90MB 内存的 .dll.我想知道什么".dll 占用了 90MB.

I want to find out how much memory my application is using. I also want to know what part of my program is using the most memory. For example, I have a process that uses 100MB of memory, there is a .dll in that process that is using 90MB of memory. I would like to know "what" .dll takes that 90MB.

我想取这个值并在我的程序中使用它;我想做一个服务器,可以查看各个部分的内存使用情况.

I want to take this value and use it in my program; I want to make a server where you can view the memory usage of separate parts.

此应用程序将在 Windows 上运行.

This application is going to run on Windows.

推荐答案

这个问题完全取决于操作系统.

The question is utterly operating system dependent.

(我假设 DLL 会转换为 Linux 世界中动态加载的库和 ELF 共享对象)

(I assume that DLL translates to dynamically loaded libraries and ELF shared objects in the Linux world)

对于 Linux 应用程序,您的应用程序可以顺序读取 /proc/self/maps 文本伪文件.

For a Linux application, your application can sequentially read the /proc/self/maps textual pseudo-file.

如果您知道您的应用程序进程 ID 是 1234,您还可以阅读 /proc/1234/maps 文件,例如通过在终端中输入

If you know that your application process id is 1234, you can also read the /proc/1234/maps file, e.g. by typing in a terminal

 cat /proc/1234/maps

还有 /proc/self/smaps/proc/1234/smaps 稍微详细一点.

There are also /proc/self/smaps and /proc/1234/smaps which are slightly more detailed.

这篇关于在运行时,如何以编程方式确定动态链接库使用了多少内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆