Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r65435 - sandbox/memory/libs/memory/examples/pool
From: xushiweizh_at_[hidden]
Date: 2010-09-16 03:30:35


Author: xushiwei
Date: 2010-09-16 03:30:33 EDT (Thu, 16 Sep 2010)
New Revision: 65435
URL: http://svn.boost.org/trac/boost/changeset/65435

Log:
1. windows 64bits -- to do
2. class MemoryState;
Text files modified:
   sandbox/memory/libs/memory/examples/pool/simple_examples.cpp | 65 ++++++---------------------------------
   1 files changed, 11 insertions(+), 54 deletions(-)

Modified: sandbox/memory/libs/memory/examples/pool/simple_examples.cpp
==============================================================================
--- sandbox/memory/libs/memory/examples/pool/simple_examples.cpp (original)
+++ sandbox/memory/libs/memory/examples/pool/simple_examples.cpp 2010-09-16 03:30:33 EDT (Thu, 16 Sep 2010)
@@ -10,7 +10,6 @@
 // See http://www.boost.org/libs/memory/index.htm for documentation.
 //
 #include <boost/memory.hpp>
-#include <boost/memory/object_pool.hpp>
 
 // -------------------------------------------------------------------------
 
@@ -21,8 +20,8 @@
 void testPool()
 {
         int i;
- boost::memory::pool alloc(sizeof(int));
- boost::memory::pool alloc2(sizeof(double));
+ NS_BOOST_MEMORY::pool alloc(sizeof(int));
+ NS_BOOST_MEMORY::pool alloc2(sizeof(double));
 
         int* p[3000];
         for (i = 0; i < countof(p); ++i)
@@ -53,9 +52,9 @@
 void testScopedPool()
 {
         int i;
- boost::memory::block_pool recycle;
- boost::memory::scoped_pool alloc(recycle, sizeof(int));
- boost::memory::scoped_pool alloc2(alloc.get_alloc(), sizeof(double));
+ NS_BOOST_MEMORY::block_pool recycle;
+ NS_BOOST_MEMORY::scoped_pool alloc(recycle, sizeof(int));
+ NS_BOOST_MEMORY::scoped_pool alloc2(alloc.get_alloc(), sizeof(double));
 
         void* p[3000];
         for (i = 0; i < countof(p); ++i)
@@ -78,63 +77,21 @@
                 alloc.allocate();
 }
 
-int g_nConstruct = 0;
-int g_nDestruct = 0;
-
-struct Obj
-{
- char m_val[100];
-
- Obj() { ++g_nConstruct; m_val[1] = 0x23; }
- Obj(int val) { ++g_nConstruct; }
- ~Obj() { ++g_nDestruct; }
-};
-
-void testObjectPool()
+void testPools()
 {
- boost::memory::object_pool<int> alloc;
- int* p1 = alloc.construct();
- int* p2 = alloc.construct();
- int* p3 = BOOST_NEW(alloc, int)(30);
- BOOST_MEMORY_ASSERT(*p3 == 30);
+ NS_BOOST_MEMORY::pools alloc;
 
- {
- boost::memory::object_pool<Obj> alloc2;
- for (int i = 0; i < 3000; ++i)
- {
- Obj* o1 = alloc2.construct();
- Obj* o2 = alloc2.construct();
- Obj* o3 = BOOST_NEW(alloc2, Obj)(20);
- Obj* o4 = BOOST_NEW(alloc2, Obj)(25);
- alloc2.destroy(o2);
- alloc2.destroy(o3);
- }
- }
- BOOST_MEMORY_ASSERT(g_nConstruct == g_nDestruct);
- if (g_nConstruct != g_nDestruct)
- printf("ERROR: memory leaks!\n");
-}
-
-void testScopedPools()
-{
- size_t i;
- boost::memory::block_pool recycle;
- boost::memory::scoped_pools alloc(recycle);
-
- void* p[22];
- for (i = 0; i < countof(p); ++i)
- p[i] = alloc.get_pool(i * 7).allocate();
- for (i = 3; i < countof(p) - 2; ++i)
- alloc.get_pool(i * 7).deallocate(p[i]);
+ void* p = alloc.allocate(134);
+ alloc.deallocate(p, 134);
+ //alloc.deallocate(p, 134);
 }
 
 int main()
 {
         NS_BOOST_MEMORY::enableMemoryLeakCheck();
 
- testScopedPools();
         testPool();
         testScopedPool();
- testObjectPool();
+ testPools();
         return 0;
 }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk