View Single Post
Old 08-09-2007, 10:57 PM  
neoxed
Too much time...
 
Join Date: May 2003
Posts: 1,326
Default

One thing to keep in mind with malloc/free is the horrible scalability they have in long running applications. If the process is running for only a few minutes or hours it goes unnoticed, but in long term processes performance will degrade. On x86-32 platforms, the Microsoft CRT uses a default heap without any kind of system to prevent heap fragmentation for malloc/free. On x86-64 (amd64/intel64/x64) and IA-64 platforms, the Microsoft CRT uses a low fragmentation heap.

Heap fragmentation is caused by the allocating and freeing of various sizes of blocks over a period of time. The available heap memory becomes broken down into small unusable and non-contiguous blocks leading to failed allocations. This is something all network server applications should take into serious consideration, due to the small blocks allocated for client structures and large blocks allocated for transfer buffers, and the fact that the processes generally run for weeks. (Just google "heap fragmentation").

I would suggest at the very least using the Heap APIs from WinBase (HeapAlloc/HeapFree). Once you create your own heap, call HeapSetInformation to enable LFH (low-fragmentation heap). This alternate heap maintains buckets of previously allocated memory blocks, arranged by size, to prevent fragmentation. The only catch is that the HeapSetInformation API, and thus LFH, are only available on Windows XP or later.
neoxed is offline