Preallocating memory space for programs use

c++, memory-management

Solution

You seem to be looking for a memory pool - http://www.codeproject.com/Articles/27487/Why-to-use-memory-pool-and-how-to-implement-it

Note that you can pre-allocate some memory and then use placement new to prevent multiple allocations.

Problem

In my Windows' C++ program, I allocate several small objects on heap (thousands) by calling new CMyClass() The performance seems to get affected due to this. Is there a way to preallocate some minimum memory in heap for the program's use so that the OS starts allocating from this preallocated space when ever I call new CMyClass() to improve the performance? Thanks.

Original source