it's much slower when using boost::pool_allocator and boost::object_pool
-
the test result on my computer:
//case 1
2153 // not using pool
16 // using pool
//case 2
15 // not using pool
32 // using pool
// case 3
2668 // not using pool
14976 // using pool
Press any key to continue . . .main.cpp
#include #include "test.h"
int wmain()
{
test0(10000);
test1(10000);
test2(10000);
test3(10000);
test4(10000);
test5(10000);
system("pause");
return 0;
}test.h
#pragma once
void test0(int loops);
void test1(int loops);
void test2(int loops);
void test3(int loops);
void test4(int loops);
void test5(int loops);test.cpp
#include
#include
#include
#include
#include
#include
#include "test.h"using namespace std;
class AAA
{
public:
AAA()
{
// cout << "con" << endl;
}
~AAA()
{
// cout << "descon" << endl;
}
public:
int a;
char b;
short int c;
vector d;
};void test0(int loops)
{
char ** p = new char*[loops];DWORD tick = GetTickCount(); for (int i=0; i memory\_pool(32); for (int i=0; i v; for (int i=0; i > v; for (int i=0; i obj\_pool; for (int i=0; i
-
the test result on my computer:
//case 1
2153 // not using pool
16 // using pool
//case 2
15 // not using pool
32 // using pool
// case 3
2668 // not using pool
14976 // using pool
Press any key to continue . . .main.cpp
#include #include "test.h"
int wmain()
{
test0(10000);
test1(10000);
test2(10000);
test3(10000);
test4(10000);
test5(10000);
system("pause");
return 0;
}test.h
#pragma once
void test0(int loops);
void test1(int loops);
void test2(int loops);
void test3(int loops);
void test4(int loops);
void test5(int loops);test.cpp
#include
#include
#include
#include
#include
#include
#include "test.h"using namespace std;
class AAA
{
public:
AAA()
{
// cout << "con" << endl;
}
~AAA()
{
// cout << "descon" << endl;
}
public:
int a;
char b;
short int c;
vector d;
};void test0(int loops)
{
char ** p = new char*[loops];DWORD tick = GetTickCount(); for (int i=0; i memory\_pool(32); for (int i=0; i v; for (int i=0; i > v; for (int i=0; i obj\_pool; for (int i=0; i
-
Richard MacCutchan wrote:
Is there supposed to be a question here**?**
I see a question mark there. :-D Pardon the silly humour, it's a rainy Sunday, here...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Richard MacCutchan wrote:
Is there supposed to be a question here**?**
I see a question mark there. :-D Pardon the silly humour, it's a rainy Sunday, here...
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
CPallini wrote:
Pardon the silly humour, it's a rainy Sunday, here.
I didn't think you would notice the rain after yesterday's brilliance by your team.
I must get a clever new signature for 2011.
Well, beating France is always a great satisfaction for all. Anyway, I know, you're more used to. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
the test result on my computer:
//case 1
2153 // not using pool
16 // using pool
//case 2
15 // not using pool
32 // using pool
// case 3
2668 // not using pool
14976 // using pool
Press any key to continue . . .main.cpp
#include #include "test.h"
int wmain()
{
test0(10000);
test1(10000);
test2(10000);
test3(10000);
test4(10000);
test5(10000);
system("pause");
return 0;
}test.h
#pragma once
void test0(int loops);
void test1(int loops);
void test2(int loops);
void test3(int loops);
void test4(int loops);
void test5(int loops);test.cpp
#include
#include
#include
#include
#include
#include
#include "test.h"using namespace std;
class AAA
{
public:
AAA()
{
// cout << "con" << endl;
}
~AAA()
{
// cout << "descon" << endl;
}
public:
int a;
char b;
short int c;
vector d;
};void test0(int loops)
{
char ** p = new char*[loops];DWORD tick = GetTickCount(); for (int i=0; i memory\_pool(32); for (int i=0; i v; for (int i=0; i > v; for (int i=0; i obj\_pool; for (int i=0; i
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.
-
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.