Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preallocating memory space for programs use

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.

like image 571
Gautam Jain Avatar asked May 18 '12 12:05

Gautam Jain


1 Answers

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.

like image 172
Luchian Grigore Avatar answered Oct 13 '22 02:10

Luchian Grigore