I\'m developing a VC++ NT service that is meant to operate continuously for many months. It uses VC++ runtime heap intensively. Clearly heap fragmentation can at some point
The easiest way to detect fragmentation is to determine your largest allocation that your program will ever make and then to allocate at least twice that amount every now and again. if the allocation fails i.e. returns NULL AND your heap usage as determined by code - something like this on Windows
PROCESS_MEMORY_COUNTERS counters;
if(GetProcessMemoryInfo(process, &counters, sizeof(counters))){
result = counters.WorkingSetSize;
}
is less than some percentage of system memory usually 75% then you definitely have a fragmentation issue.