我想确定动态链接库使用了多少内存 [英] I want to determine how much memory is used by dynamically-linked libraries

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

问题描述

我想找出哪些库使用的内存最多.我想在我的应用程序中制作一种内存记录器.这需要以编程方式查找自己进程中哪些库使用了多少内存.

I want to find out what libraries are using the most memory. I want to make a kind of memory logger in my application. This needs to look up programmatically how much memory is used by what libraries in its own process.

例如,我有一个使用 10MB 内存的程序,其中有一个 .dll 使用了 9MB 内存.我想查看所有 dll 以及它们使用了多少内存.此应用程序将在 Windows 上运行.一切都需要以编程方式完成.

For example, I have a program that is using 10MB of memory, there is a .dll in there that is using 9MB of memory. I would like to see all the dll's and how many memory they use. This application is going to run on Windows. Everything needs to be done programmatically.

推荐答案

不确定这是否是最简单的方法,但也许您应该在加载每个库后立即挂钩内存分配 WinAPI 函数.然后在您的钩子中,您将能够进行必要的计数看看 Microsoft Detours 库作为一个很好的挂钩框架 (http://research.microsoft.com/en-us/projects/detours/).它通常不是免费的,但可以免费用于研究、非商业和非生产用途"

Not sure if it is the simplest approach, but maybe you should hook memory allocation WinAPI functions right after loading each library. Then in your hook you will be able to do necessary counting Take a look at Microsoft Detours library as a good hooking framework (http://research.microsoft.com/en-us/projects/detours/). It is generally not free, but is available for free "for research, non-commercial, and non-production use"

挂钩哪些实际函数实际上取决于需要跟踪的 dll.

Which actual functions to hook actually depends on the dlls that need to be tracked.

如果所有这些都是使用动态链接的 MSVC 运行时编译的,则必须挂钩 malloc()/free()/calloc()/realloc() 系列函数.如果它是针对运行时静态链接的,或者不是使用 MS VC 编译的,则必须挂钩与内存相关的 WinAPI 调用,例如 HeapAlloc/HeapCreate/HeapDestroy/HeapFree/heapReAlloc/VirtualAlloc/VirtualFree(我只是寻找与内存相关的msvcr100.dll 从 kernel32.dll 导入的函数)

If all of them are compiled with MSVC runtimes linked dynamically you'd have to hook malloc() / free() / calloc() / realloc() series of functions. If it was linked statically against runtime, or was not compiled with MS VC, you'll have to hook memory-related WinAPI calls such as HeapAlloc / HeapCreate / HeapDestroy / HeapFree / heapReAlloc / VirtualAlloc / VirtualFree (I just looked for memory-related functions that msvcr100.dll imports from kernel32.dll)

这篇关于我想确定动态链接库使用了多少内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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