12 years ago
Local Heap live counts after FormatMessage,LocalFree
I am running Allocation Profiler on the following code.( VS2003 C++ console app).
options:
Check system memory allocations
Check memory bounds
Collect Stack info: none
Thread model: win32
int _tmain(int argc, _TCHAR* argv[])
{
for(int i=0; i<1000; i++)
{
LPSTR msg = "dum de dum de dum.";
LPVOID lpGrvBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_STRING |
FORMAT_MESSAGE_IGNORE_INSERTS,
msg,
0,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpGrvBuf,
0,
NULL
);
LocalFree(lpGrvBuf);
}
//pause - get AQTime results here
std::cout << "Hit enter to continue";
std::cin.get();
return 0;
}
After running I get the following Class Data entry for LocalHeap:
Module Name | Class Name | Namespace | Token | Finalizable |
LOCALHEAPTEST.EXE | Local heap | | 0 | False |
Total Created | Peak Created | Live Count | Total Size | Peak Size | Live Size
1000 | 1000 | 1000 | 0 | 0 | 0
My question is why is LiveCount 1000, when LocalFree is called after each FormatMessage call. LocalAlloc is called from FormatMessage.
If I replace the FormatMessage call with:
lpGrvBuf = LocalAlloc(LMEM_FIXED,20)
Then LiveCount is in fact zero.
My concern is whether the Live object count indicates a resource drain of some kind, even though the associated memory sizes are zero?
(This is an excerpt from a windows service, so it may run continuously with out being closed.)
options:
Check system memory allocations
Check memory bounds
Collect Stack info: none
Thread model: win32
int _tmain(int argc, _TCHAR* argv[])
{
for(int i=0; i<1000; i++)
{
LPSTR msg = "dum de dum de dum.";
LPVOID lpGrvBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_STRING |
FORMAT_MESSAGE_IGNORE_INSERTS,
msg,
0,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpGrvBuf,
0,
NULL
);
LocalFree(lpGrvBuf);
}
//pause - get AQTime results here
std::cout << "Hit enter to continue";
std::cin.get();
return 0;
}
After running I get the following Class Data entry for LocalHeap:
Module Name | Class Name | Namespace | Token | Finalizable |
LOCALHEAPTEST.EXE | Local heap | | 0 | False |
Total Created | Peak Created | Live Count | Total Size | Peak Size | Live Size
1000 | 1000 | 1000 | 0 | 0 | 0
My question is why is LiveCount 1000, when LocalFree is called after each FormatMessage call. LocalAlloc is called from FormatMessage.
If I replace the FormatMessage call with:
lpGrvBuf = LocalAlloc(LMEM_FIXED,20)
Then LiveCount is in fact zero.
My concern is whether the Live object count indicates a resource drain of some kind, even though the associated memory sizes are zero?
(This is an excerpt from a windows service, so it may run continuously with out being closed.)