1

A customer has some memory usage requirements of our application. They note that while our committed memory is reasonable, the reserved memory is high. They suspect this is because the CRT heap grows as we allocate memory, but the CRT isn't returning pages to the OS when the memory is deallocated. We are just using built-in operator new/delete/new[]/delete[] - along with a little usage of malloc/free.

They ask, "Does your memory manager call _heapmin at some point to compact the heap?"

ummm, we don't explicitly call _heapmin. Should we? Are there any rules of thumb for its use?

sean e
  • 11,792
  • 3
  • 44
  • 56
  • 3
    Well, if they want it free'd to the OS, I guess call it periodically. I don't see what the issue is though. If the OS needs the memory, it'll take it anyway. By giving it up, if *you* need the memory, you're just slowing yourself down since you gave it away. It's a lose-lose. – GManNickG Feb 17 '10 at 04:54
  • Does reserved memory really matter? It's been marked to the OS as being empty so it shouldn't matter how much reserved memory you have. – Billy ONeal Feb 17 '10 at 16:10
  • That's what I'm wondering myself... – sean e Feb 17 '10 at 19:16

1 Answers1

0

As you are using the CRT memory manager there is no need to call it explicitly the OS will manage this.

Andy
  • 1,035
  • 2
  • 9
  • 14
  • 2
    The CRT is built on top of the Windows API, and the OS cannot do anything, without the CRT explicitly requesting it. As it turns out, the CRT never decommits pages that are freed by the application. Over time, the CRT could consume a large portion of the limited address space, to the point where other operations (that do not even need memory, just address space, like [MapViewOfFile](https://msdn.microsoft.com/en-us/library/windows/desktop/aa366761.aspx)) start failing. `_heapmin` should help with this situation, except, in recent versions, it doesn't do anything, unfortunately. – IInspectable Jun 08 '15 at 21:42