Wednesday, August 25, 2010

allocator ---(2)

Most of the situation the stl default allocator is good enough to handle memory allocation.
But I still did a test on BOOST allocator and STL default allocator.
The result is BOOST pool_allocator is faster and more robust than STL default allocator.

class a
{
public:
a(){}
private:
int t;
//long t1;
};
BOOST_AUTO_TEST_CASE( pool )

{

boost::shared_ptr<Timer> timer(new Timer());
std::vector<a,boost::pool_allocator<a>> v(100000000);
//boost::singleton_pool<boost::pool_allocator_tag, sizeof(int)>::release_memory();

std::cout<<"Time spent on pool_allocator with constructor call: " << timer->elapsed()<<std::endl;


timer->restart();
std::vector<a> v2(100000000);
std::cout<<"Time spent on default allocator with constructor call: " << timer->elapsed()<<std::endl;

}











0 comments:

Post a Comment