开发者

Why does reserved virtual memory grow while virtual memory currently in use doesn't grow?

My application gets bad_alloc exception. Resource Monitor shows that virtual memory reserved by OS (Commit) exceeded 2G. However, virtual memory currently in use by the process (Working Set) is pretty small (at time of crash it can be around 200000 Kb). How it can happen? I noticed that when program starts those two are almost of the same size (Commit is a little bit bigger). But with time passing difference grows and it seems to me because when the second memory (Working Set) increases, the fist one (Commit) increases too. But when the second one decreases, the first one doesn't go back. I use three different computers and everywhere have this behaviour. I use Windows 7 and program is written in C++.

What could cause such a behaviour? T开发者_JS百科hank you


This is sometimes caused by the memory allocation pattern of your application. If, for example, you have data structures that are always growing, and defer some time the deletion of the previous buffers (those that run out of space), then you can observe this behavior with the heap. This is caused because maybe when your program tries to allocate a greater chunk of memory, it has no space before the actual buffer, so it has to grow the allocated heap to allocate the greater chunk. Maybe then afterwards you delete the old buffer, but the heap has increased already. Maybe even after, in another loop, you use pieces of the freed memory that again don't leave enough space for the next bigger block, and so on, so the memory is exhausted.

It would help to show a rough description of the inner workings of your program in terms of memory management.


The "Working Set" is the amount of pages that is made visible by the OS to your application. The OS tries to reduce it all the time.

If you allocate memory and don't use it, the working set will be small. But the memory you allocate has to fit in the virtual adress space of your application anyway.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜