积极答复者
取得堆内存大小

问题
答案
-
__开头的是微软的C++扩展,不是标准的一部分。
一个程序可以有多个堆,比如静态链接CRT的每个DLL都有一个堆,动态链接同一个版本的CRT的代码共享一个CRT堆、托管代码共享一个托管堆等等。你可以用_heapwalk遍历在当前模块使用的CRT堆上分配的内存。
The following is signature, not part of post
Please mark the post answered your question as the answer, and mark other helpful posts as helpful.
Visual C++ MVP- 已标记为答案 Aland LiModerator 2010年5月11日 12:30
-
CRT的内存管理没有提供这方面的接口。你可以自己写一个提供此功能的内存管理器来替换CRT。
The following is signature, not part of post
Please mark the post answered your question as the answer, and mark other helpful posts as helpful.
Visual C++ MVP- 已标记为答案 Aland LiModerator 2010年5月11日 12:30
全部回复
-
__开头的是微软的C++扩展,不是标准的一部分。
一个程序可以有多个堆,比如静态链接CRT的每个DLL都有一个堆,动态链接同一个版本的CRT的代码共享一个CRT堆、托管代码共享一个托管堆等等。你可以用_heapwalk遍历在当前模块使用的CRT堆上分配的内存。
The following is signature, not part of post
Please mark the post answered your question as the answer, and mark other helpful posts as helpful.
Visual C++ MVP- 已标记为答案 Aland LiModerator 2010年5月11日 12:30
-
__开头的是微软的C++扩展,不是标准的一部分。
一个程序可以有多个堆,比如静态链接CRT的每个DLL都有一个堆,动态链接同一个版本的CRT的代码共享一个CRT堆、托管代码共享一个托管堆等等。你可以用_heapwalk遍历在当前模块使用的CRT堆上分配的内存。
The following is signature, not part of post
Please mark the post answered your question as the answer, and mark other helpful posts as helpful.
Visual C++ MVP
谢谢您的回复。让我了解了不少。_heapwalk在很多时候是一个有用的函数,但我希望能知道若我给定一个指向堆的指针(由new type[]分配),有函数能判断该指针指向的位置所分配的大小吗?
再提出一个关于栈的问题:
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#include<iostream>
using namespace std;
void out(int * p)
{
cout<<sizeof(p)/sizeof(*p)<<endl;
}
int main()
{
int tmp[10];
cout<<sizeof(tmp)/sizeof(*tmp)<<endl;
cout<<"~~~~~~~~~~~~~~~"<<endl;
out(tmp);
}//~~~~~~~~~~~~~~~~~~~~~~~~~~~~
关于sizeof(tmp)/sizeof(*tmp)的机制到底是怎么样的呢?
tmp应该是一个指针,为一个int大小,但在main函数中,该语句可以得到数组的大小(10),而当我传递了这个指针到其他函数之后,却发现这个指针在其他函数中被“正常”的解释了。
请问这是为什么?
-
CRT的内存管理没有提供这方面的接口。你可以自己写一个提供此功能的内存管理器来替换CRT。
The following is signature, not part of post
Please mark the post answered your question as the answer, and mark other helpful posts as helpful.
Visual C++ MVP- 已标记为答案 Aland LiModerator 2010年5月11日 12:30