/*************************************************************************** * * Copyright (c) 2009 Baidu.com, Inc. All Rights Reserved * $Id: bsl_test_mempool_stable.h,v 1.1 2009/01/06 15:05:14 xiaowei Exp $ * **************************************************************************/ /** * @file bsl_test_mempool_stable.h * @author xiaowei(com@baidu.com) * @date 2009/01/06 22:29:11 * @version $Revision: 1.1 $ * @brief * **/ #ifndef __BSL_TEST_MEMPOOL_STABLE_H_ #define __BSL_TEST_MEMPOOL_STABLE_H_ #include #include #include #include #include #include #include #include #define ALLOC(type) bsl::pool_allocator #define VECTOR(type) std::vector #define MAP(key, value) \ std::map, ALLOC(value) > class bsl_test_mempool_stable : public CxxTest::TestSuite { public: void test_normal() { bsl::xcompool stlp; stlp.create(1<<16); bsl::xcompool pool; pool.create(); for (int idx=0; idx<3; ++idx) { { ALLOC(void *) ap(&stlp); VECTOR(void *) vec (ap); ALLOC(size_t) sp(&stlp); std::less eq; MAP(void *, size_t) vmp(eq, sp); long total = 0; for (int i=0; i<1<<16; ++i) { int lp = rand()%100; for (int j=0; j 0) { if (vec.size() == 0) break; rel -= vmp[vec.back()]; pool.free (vec.back(), vmp[vec.back()]); vec.pop_back(); } } } stlp.clear(); pool.clear(); std::cout< eq; MAP(void *, size_t) vmp(eq, sp); long total = 0; for (int i=0; i<1<<16; ++i) { int lp = rand()%100; for (int j=0; j 0) { if (vec.size() == 0) break; rel -= vmp[vec.back()]; pool.free (vec.back(), vmp[vec.back()]); vec.pop_back(); } } } std::cout<