Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r53215 - in sandbox/memory: boost libs/memory/examples/stl_containers
From: xushiweizh_at_[hidden]
Date: 2009-05-23 13:30:37


Author: xushiwei
Date: 2009-05-23 13:30:36 EDT (Sat, 23 May 2009)
New Revision: 53215
URL: http://svn.boost.org/trac/boost/changeset/53215

Log:
1. bug fix: stl_allocator::deallocate
2. example: stl_containers - testPoolsAllocSet
Text files modified:
   sandbox/memory/boost/memory.hpp | 4 ++--
   sandbox/memory/libs/memory/examples/stl_containers/stl_containers.cpp | 16 ++++++++++++++++
   2 files changed, 18 insertions(+), 2 deletions(-)

Modified: sandbox/memory/boost/memory.hpp
==============================================================================
--- sandbox/memory/boost/memory.hpp (original)
+++ sandbox/memory/boost/memory.hpp 2009-05-23 13:30:36 EDT (Sat, 23 May 2009)
@@ -128,8 +128,8 @@
 
         pointer allocate(size_type count, const void* = NULL)
                 { return (pointer)m_alloc->allocate(count * sizeof(Type)); }
- void deallocate(void* p, size_type cb)
- { m_alloc->deallocate(p, cb); }
+ void deallocate(void* p, size_type count)
+ { m_alloc->deallocate(p, count * sizeof(Type)); }
         void construct(pointer p, const Type& val)
                 { new(p) Type(val); }
         void destroy(pointer p)

Modified: sandbox/memory/libs/memory/examples/stl_containers/stl_containers.cpp
==============================================================================
--- sandbox/memory/libs/memory/examples/stl_containers/stl_containers.cpp (original)
+++ sandbox/memory/libs/memory/examples/stl_containers/stl_containers.cpp 2009-05-23 13:30:36 EDT (Sat, 23 May 2009)
@@ -17,6 +17,7 @@
 #include <cstdio>
 
 #include <boost/memory.hpp>
+#include <boost/memory/pools_alloc.hpp>
 
 using NS_BOOST_MEMORY::stl_allocator;
 
@@ -64,11 +65,26 @@
                 s.insert(std::pair<int, int>(i, i));
 }
 
+void testPoolsAllocSet()
+{
+ typedef NS_BOOST_MEMORY::block_pool block_pool;
+ typedef NS_BOOST_MEMORY::pools_alloc<NS_BOOST_MEMORY_POLICY::scoped> scoped_pools;
+ typedef NS_BOOST_MEMORY::stl_allocator<int, scoped_pools> allocator;
+
+ printf("\n===== Set (pools_alloc) =====\n");
+ block_pool recycle;
+ scoped_pools alloc(recycle);
+ std::set<int, std::less<int>, allocator> s(std::less<int>(), alloc);
+ for (int i = 0; i < Count; ++i)
+ s.insert(i);
+}
+
 int main()
 {
         testDeque();
         testList();
         testSet();
+ testPoolsAllocSet();
         testMap();
 
         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