object_pool use ordered_malloc ordered_free. why?
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 <boost/pool/object_pool.hpp> #include <vector> #include <iostream> #include <time.h> #include <stdlib.h> struct Some { std::string ss; int ii; char cc[32]; }; int main(int argc, char * argv[]) { boost::object_pool<Some> pool; std::vector<Some*> v_Some; int count = 20000; time_t t = time(0); std::cout << ctime(&t) << std::endl; for (int i=0; i<count; ++i) { Some * s = pool.construct(); if (s) v_Some.push_back(s); else break; } t = time(0); std::cout << v_Some.size() << ctime(&t) << std::endl; if (argc > 1) { // fast for (std::vector<Some*>::reverse_iterator it = v_Some.rbegin(); it != v_Some.rend(); ++it) pool.destroy(*it); } else { // slow for (std::vector<Some*>::iterator it = v_Some.begin(); it != v_Some.end(); ++it) pool.destroy(*it); } t = time(0); std::cout << ctime(&t) << std::endl; return 0; }
participants (1)
-
wugui