Archive for February, 2009

Snippet: Enable Low Fragmentation Heap for all heaps

Monday, February 23rd, 2009

The following code is a code snippet that enable the Low Fragmentation Heap for all heaps. Remembers that a process has at last one heap but for example a CRT console application has practically at last two heaps. The first heap is default heap of process and the second is the CRT heap. If you use a lot of external DLLs is very common that one of this DLL allocate a private heap.

   1:  // code snippet that try to enable LFH for all heaps of your runnig program.
   2:      HANDLE* hHeaps = NULL;
   3:      int numHeap = GetProcessHeaps(0, NULL);
   4:      if(numHeap > 0)
   5:      {
   6:          ULONG ulEnableLFH = 2;
   7:          hHeaps = (HANDLE*)malloc(sizeof(HANDLE)*numHeap);
   8:          if(GetProcessHeaps(numHeap, hHeaps) == numHeap)
   9:          {
  10:              for(int i = 0; i < numHeap; i++)
  11:              {
  12:                  if(!HeapSetInformation(hHeaps[i], HeapCompatibilityInformation, &ulEnableLFH, sizeof(ulEnableLFH)))
  13:                  {
  14:                      printf("Failed to enable LFH for heap %d.", i);
  15:                  }
  16:              }
  17:          }
  18:          else
  19:          {
  20:              // quite strange !!!
  21:          }
  22:          free(hHeaps);
  23:      }

Suggested reading Windows Internals 4th edition for more details.

Analisi da riga di comando di un dump

Wednesday, February 11th, 2009

Nell’ultimo week-end, un applicazione in sviluppo è terminata inaspettatamente un infinità di volta. Generando un gran numero di memory dump, tutti di dimensioni considerevoli. La domanda sorge spontanea.
Come posso analizzare tutti questi dump senza sprecare un sacco del mio tempo?

(more…)