I'm trying to better understand why a bunch of Windows Vista behaves the way it does. Consider the following very simple program:
#include <vector> #define NUM_ALLOCS 10000000 int _tmain(int argc, _TCHAR* argv[]) { for (int iteration=0; iteration<10000; ++iteration) { std::vector<unsigned char *> buffer; buffer.reserve(NUM_ALLOCS); for (int i=0;i<NUM_ALLOCS;++i) { buffer.push_back(new unsigned char); } for (int i=0;i<NUM_ALLOCS;++i) { delete buffer[i]; } } return 0; }
This is basically a loop that allocates many 1 byte blocks for each iteration, and then frees them. Naturally, the memory usage of this program increases when buffers are allocated, and then down when the buffers are freed.
The behavior that I see in the 64-bit version of Windows Vista is that peak memory usage (as reported by the task manager or vmmap ) remains roughly constant over time, while the smallest memory consumption grows until it approaches peak memory.
On a 64-bit version of Windows 7, the lowest memory used does not grow over time.
Edit: I tested on two 64-bit Windows Vista machines with 8 GB / 4 GB RAM and one 64-bit Windows 7 machine with 4 GB RAM. I tested an 8 gigabyte machine with low and high memory usage.
Edit: I built the above example with Visual Studio 2005 and 2010 with the same result.
This example does not bring anything useful, but the memory usage scenario is similar (albeit highly condensed) to my program, for which I tried to understand why it uses much more memory than it actually does. From what I can tell, the memory is stored by the heap manager.
Does anyone know about heap mechanisms? Do I need to do something to convince the heap manager to completely free the heap memory used? Are there alternative strategies that I should use, for example, to create a separate heap and then destroy it?
Any comments or ideas appreciated!
memory-management heap windows windows-7 windows-vista
villintehaspam
source share