boost_1_28_0
if construct only, and freeall in ~object_pool. i think it is good.
can i use object_pool to replace 'new delete'?
the destroy is slow.
thank for any advice.
newbie and not good at english.
full test code:
#include
#include <vector>
#include <iostream>
#include
#include
struct Some
{
std::string ss;
int ii;
char cc[32];
};
int main(int argc, char * argv[])
{
boost::object_pool<Some> pool;
std::vector v_Some;
int count = 20000;
time_t t = time(0); std::cout << ctime(&t) << std::endl;
for (int i=0; i 1)
{ // fast
for (std::vector::reverse_iterator it = v_Some.rbegin();
it != v_Some.rend(); ++it)
pool.destroy(*it);
}
else
{ // slow
for (std::vector::iterator it = v_Some.begin();
it != v_Some.end(); ++it)
pool.destroy(*it);
}
t = time(0); std::cout << ctime(&t) << std::endl;
return 0;
}