Click here to Skip to main content
15,902,275 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
Questionit's much slower when using boost::pool_allocator and boost::object_pool Pin
followait12-Mar-11 19:05
followait12-Mar-11 19:05 
AnswerRe: it's much slower when using boost::pool_allocator and boost::object_pool Pin
Richard MacCutchan12-Mar-11 22:45
mveRichard MacCutchan12-Mar-11 22:45 
GeneralRe: it's much slower when using boost::pool_allocator and boost::object_pool Pin
CPallini13-Mar-11 1:44
mveCPallini13-Mar-11 1:44 
GeneralRe: it's much slower when using boost::pool_allocator and boost::object_pool Pin
Richard MacCutchan13-Mar-11 2:06
mveRichard MacCutchan13-Mar-11 2:06 
GeneralRe: it's much slower when using boost::pool_allocator and boost::object_pool Pin
CPallini13-Mar-11 3:02
mveCPallini13-Mar-11 3:02 
GeneralRe: it's much slower when using boost::pool_allocator and boost::object_pool Pin
followait13-Mar-11 1:55
followait13-Mar-11 1:55 
GeneralRe: it's much slower when using boost::pool_allocator and boost::object_pool Pin
Richard MacCutchan13-Mar-11 2:09
mveRichard MacCutchan13-Mar-11 2:09 
AnswerRe: it's much slower when using boost::pool_allocator and boost::object_pool Pin
Stefan_Lang22-Mar-11 0:20
Stefan_Lang22-Mar-11 0:20 
Sorry for being late to reply, but since there doesn't seem to be a useful answer yet I thought I'd add some explanations.

Looking at your code, the results you got from test0() and test(1) look ok, but those from test2() and test(3) are probably useless: std::vector has it's own method of maintaining a buffer for cases of repeated resizing, which is very similar to the one used in boost::pool. Thus it will not allocate memory once per loop, in fact there will probably only be a few dozen allocations forwarded to the boost::pool allocator. If you want to ensure one allocation per loop count, then I suggest you use std::list instead.

I am not quite sure why object_pool is so slow, but I suspect the reason is the method free(). This method, to my knowledge, is disabled for pools of standard objects, because it is very inefficient (it is O(n) where n is the number of objects in the pool). The standard memory allocator (i. e. new/delete)), although quite slow, is still only O(1)! Therefore, the only sensible way to use boost::object_pool at this time is to not call the destroy() method at all! Don't worry, the moment the pool gets destroyed, all the objects will still be destructed properly, but that will be much more efficient than destroying each object individually.

I've tried to use boost::pool 2 years ago for our application, but, in similar tests, found that it wasn't usable for our purposes. I eventually created my own implementation that dynamically frees (and destructs) objects at O(1), and considerably faster than new/delete (tested for up to 10 million allocations). If that's what you're looking for, I could make this into an article. It might take some time though.
GeneralRe: it's much slower when using boost::pool_allocator and boost::object_pool Pin
followait25-Mar-11 20:13
followait25-Mar-11 20:13 
QuestionCall a extern variable from Application class Pin
Jokcy12-Mar-11 16:35
Jokcy12-Mar-11 16:35 
AnswerRe: Call a extern variable from Application class Pin
David Crow12-Mar-11 17:04
David Crow12-Mar-11 17:04 
GeneralRe: Call a extern variable from Application class Pin
Jokcy12-Mar-11 21:07
Jokcy12-Mar-11 21:07 
GeneralRe: Call a extern variable from Application class Pin
David Crow13-Mar-11 13:09
David Crow13-Mar-11 13:09 
GeneralRe: Call a extern variable from Application class Pin
Jokcy15-Mar-11 21:35
Jokcy15-Mar-11 21:35 
AnswerRe: Call a extern variable from Application class Pin
«_Superman_»12-Mar-11 17:42
professional«_Superman_»12-Mar-11 17:42 
GeneralRe: Call a extern variable from Application class [modified] Pin
Jokcy12-Mar-11 21:16
Jokcy12-Mar-11 21:16 
GeneralRe: Call a extern variable from Application class Pin
«_Superman_»12-Mar-11 22:03
professional«_Superman_»12-Mar-11 22:03 
GeneralRe: Call a extern variable from Application class Pin
Jokcy13-Mar-11 1:34
Jokcy13-Mar-11 1:34 
AnswerRe: Call a extern variable from Application class Pin
Richard MacCutchan12-Mar-11 22:44
mveRichard MacCutchan12-Mar-11 22:44 
GeneralRe: Call a extern variable from Application class Pin
Jokcy12-Mar-11 23:01
Jokcy12-Mar-11 23:01 
GeneralRe: Call a extern variable from Application class Pin
Richard MacCutchan13-Mar-11 2:03
mveRichard MacCutchan13-Mar-11 2:03 
GeneralRe: Call a extern variable from Application class Pin
Jokcy13-Mar-11 3:14
Jokcy13-Mar-11 3:14 
GeneralRe: Call a extern variable from Application class Pin
Richard MacCutchan13-Mar-11 4:23
mveRichard MacCutchan13-Mar-11 4:23 
GeneralRe: Call a extern variable from Application class Pin
Jokcy14-Mar-11 21:40
Jokcy14-Mar-11 21:40 
QuestionLoad Bitmap with CreateCompatibleBitmap Pin
leorex12-Mar-11 16:23
leorex12-Mar-11 16:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.