CRT heap in DLL

I used to believe that each process has a default heap shared by everybody in the process space including code in loaded DLL and heap manager works as described in http://msdn.microsoft.com/library/default.asp url=/library/en-us/dngenlib/html/msdn_heapmm.asp

Then I’ve found out that if DLLs are linked with CRT each has own heap manager http://msdn2.microsoft.com/en-US/library/ms235460.aspx

My questions: how those individual default heaps are allocated and grow if the DLL needs more memory What is their initial size and limit

My application is ISAPI filter/extension that runs out of memory once in a while. I want to know how to deal with the condition.




Answer this question

CRT heap in DLL

  • Noah

    Which particular newsgroup I should use Is it win32.programmer.tools or other

  • Art Heyman

    I don’t have memory leak. My problem: my multithread application (ISAPI filter/extension for IIS5) may temporary allocate a lot of memory depending on the load. When things become slow it holds on to the memory for too long and eventually runs out. Also memory fragmentation is a factor as it is allocated in different size chunks. I can see Virtual bytes counter growing up to 2GB when my application began failing and going back to normal after easing the load or restarting web publishing service. There are also other custom ISAPI applications that consume the memory.

    My questions:

    1. do the DLL CRT heaps come from the process heap and as a result are limited by it
    2. How far it can grow and do I have any control of it
    3. Would Low fragmentation heap help and how I set it considering my DLL is running in IIS5 process



  • AU.T

    So can you help me out or point to somebody who can

  • Guardian-ND

    I am pretty sure there were no memory leaks. At least all significunt memory allocation I observed in debug tool were valid. When you handle hundreds request per second, each on own thread and have slow backends you may end up eating up a lot of memory.

    The lindk you sent is to the same forum. Can you recomend other sources



  • amber1

    But than the list of allocated memory will extend to nearly 1,5gb an more!

    How can this be, even if you have hundreds of requests.

    Wrong link should be http://msdn.microsoft.com/newsgroups/



  • Vipul Modi - MSFT

    But when you run out of memory it sounds like you have one! Did you ever used a utility to check it.

    to 1.) Yes! All memory that a DLL allocates comes from the process, where the DLL is loaded.

    to 2.) The CRT heaps are not limited, so the DLL heap might grow until there is no more system memory available.

    to 3.) The low fragmentatin heap can help you only if the occupied memory leads into such a fregmentaion. Do you have such a mixture of large memory blocks, and small memory blocks that lead into such fragmentaion Did you ever walked the heap and did memory gaps show up, that indetifies the problem a s a fragmentation problem



  • simserob2

    I don't think that the heap management of the DLLs is not your problem. If you are out of memory you are out of memory and you are producing leaks.

    Use a standard technique to locale memory leaks.

    http://support.microsoft.com/default.aspx scid=kb;en-us;318263

    If a heap needs more memory it queries the OS for more memory with VirtualAlloc.

    The crt source file heapinit.c contains the creating code for the heap. AFAIK the initial size of the CRT heap is just 256 bytes. The initial size of the defaulkt process heap can be defined with the linker option /HEAP.

    HTH



  • chrismi

    I've used IIS Debug Diagnostic tool to check the memory. There was some fragmentaion and a lot of valid allocated memory blocks. I've noticed that after IIS virtual memory goes over 2GB it stops growing and I begin having memory allocation failures. It suggests that IIS heap is limited to 2GB. Can it be increased The server has 2GB of phisical memory.

  • Mark Kuether

    Actually, I take that back. These forums should be applicable for the issue.

    Thanks,
    Ayman Shoukry
    VC++ Team


  • MSDevUser

    Ask this in an Exchange forum:

    http://forums.microsoft.com/msdn/default.aspx ForumGroupID=8

    How can your DLL use such an ammount of memory
    Sorry: For me it sounds like a leak...



  • CRT heap in DLL