Configurez votre projet pour utiliser le tas Windows Low Fragmentation (LFH) en utilisant this API au début du programme. Cela peut résoudre votre problème sans plus de travail sur les implémentations personnalisées.
Exemple de code, pris directement à partir de MSDN:
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#define HEAP_LFH 2
int __cdecl _tmain()
{
BOOL bResult;
HANDLE hHeap;
ULONG HeapInformation;
//
// Note: The HeapSetInformation function is available on Windows 2000 with SP4
// only if hotfix KB 816542 is installed. To run this example on Windows 2000,
// use GetProcAddress to get a pointer to the function if available.
//
//
// Enable heap terminate-on-corruption.
// A correct application can continue to run even if this call fails,
// so it is safe to ignore the return value and call the function as follows:
// (void)HeapSetInformation(NULL, HeapEnableTerminationOnCorruption, NULL, 0);
// If the application requires heap terminate-on-corruption to be enabled,
// check the return value and exit on failure as shown in this example.
//
bResult = HeapSetInformation(NULL,
HeapEnableTerminationOnCorruption,
NULL,
0);
if (bResult != FALSE) {
_tprintf(TEXT("Heap terminate-on-corruption has been enabled.\n"));
}
else {
_tprintf(TEXT("Failed to enable heap terminate-on-corruption with LastError %d.\n"),
GetLastError());
return 1;
}
//
// Create a new heap with default parameters.
//
hHeap = HeapCreate(0, 0, 0);
if (hHeap == NULL) {
_tprintf(TEXT("Failed to create a new heap with LastError %d.\n"),
GetLastError());
return 1;
}
//
// Enable the low-fragmenation heap (LFH). Starting with Windows Vista,
// the LFH is enabled by default but this call does not cause an error.
//
HeapInformation = HEAP_LFH;
bResult = HeapSetInformation(hHeap,
HeapCompatibilityInformation,
&HeapInformation,
sizeof(HeapInformation));
if (bResult != FALSE) {
_tprintf(TEXT("The low-fragmentation heap has been enabled.\n"));
}
else {
_tprintf(TEXT("Failed to enable the low-fragmentation heap with LastError %d.\n"),
GetLastError());
return 1;
}
return 0;
}
Merci.Je pense que nedmalloc est implémenté basé sur le malloc de doug lea (dlmalloc). dlmalloc n'est pas un substitut que je recherche précédemment. Pour suivre le problème de crash nedmalloc (int5), je ne suis pas sûr. Cela s'est passé au cours d'un test de stress élevé au hasard. –
Oui, nedmalloc est basé autour de dlmalloc comme son allocateur de base, mais cela ne signifie pas que dlmalloc est la source des problèmes. selon l'en-tête si dlmalloc est à peu près une goutte de remplacement (il suffit de noter l'avertissement multithreading, utilisez ptmalloc si votre après multithreading) – Necrolis