Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r52560 - in sandbox/memory: boost boost/memory boost/memory/container libs/memory/examples/pool libs/memory/examples/simplest
From: xushiweizh_at_[hidden]
Date: 2009-04-23 07:29:04


Author: xushiwei
Date: 2009-04-23 07:29:02 EDT (Thu, 23 Apr 2009)
New Revision: 52560
URL: http://svn.boost.org/trac/boost/changeset/52560

Log:
1. add region_alloc::get_alloc, fixed_alloc::get_alloc
2. remove constructor: region_alloc(region_alloc&);

Text files modified:
   sandbox/memory/boost/memory.hpp | 20 -------------------
   sandbox/memory/boost/memory/basic.hpp | 38 ++++++++++++++++++++++++++++-------
   sandbox/memory/boost/memory/container/dcl_list.hpp | 4 +++
   sandbox/memory/boost/memory/fixed_alloc.hpp | 42 ++++++++++++++++++++++-----------------
   sandbox/memory/boost/memory/region_alloc.hpp | 24 ++++++++--------------
   sandbox/memory/libs/memory/examples/pool/simple_examples.cpp | 2 +
   sandbox/memory/libs/memory/examples/simplest/simple_examples.cpp | 4 +-
   7 files changed, 71 insertions(+), 63 deletions(-)

Modified: sandbox/memory/boost/memory.hpp
==============================================================================
--- sandbox/memory/boost/memory.hpp (original)
+++ sandbox/memory/boost/memory.hpp 2009-04-23 07:29:02 EDT (Thu, 23 Apr 2009)
@@ -58,26 +58,6 @@
 NS_BOOST_MEMORY_END
 
 // -------------------------------------------------------------------------
-// function swap_object
-
-NS_BOOST_MEMORY_BEGIN
-
-inline void swap(void* a, void* b, size_t cb)
-{
- void* t = _alloca(cb);
- memcpy(t, a, cb);
- memcpy(a, b, cb);
- memcpy(b, t, cb);
-}
-
-template <class Type>
-void swap_object(Type* a, Type* b) {
- swap(a, b, sizeof(Type));
-}
-
-NS_BOOST_MEMORY_END
-
-// -------------------------------------------------------------------------
 // class defragment
 
 NS_BOOST_MEMORY_BEGIN

Modified: sandbox/memory/boost/memory/basic.hpp
==============================================================================
--- sandbox/memory/boost/memory/basic.hpp (original)
+++ sandbox/memory/boost/memory/basic.hpp 2009-04-23 07:29:02 EDT (Thu, 23 Apr 2009)
@@ -97,7 +97,7 @@
 
 NS_BOOST_MEMORY_BEGIN
 
-class _unmanaged
+class unmanaged_
 {
 public:
         template <class Type>
@@ -108,13 +108,13 @@
 };
 
 template <class AllocT>
-class _managed
+class managed_
 {
 private:
         AllocT& m_alloc;
 
 public:
- explicit _managed(AllocT& alloc) : m_alloc(alloc) {}
+ explicit managed_(AllocT& alloc) : m_alloc(alloc) {}
 
         template <class Type>
         __forceinline Type* BOOST_MEMORY_CALL operator->*(Type* p) const
@@ -125,16 +125,16 @@
 };
 
 template <class AllocT>
-__forceinline _unmanaged BOOST_MEMORY_CALL _get_managed(AllocT& alloc, int fnZero)
+__forceinline unmanaged_ BOOST_MEMORY_CALL get_managed__(AllocT& alloc, int fnZero)
 {
- return _unmanaged();
+ return unmanaged_();
 }
 
 template <class AllocT>
 __forceinline
-_managed<AllocT> BOOST_MEMORY_CALL _get_managed(AllocT& alloc, destructor_t fn)
+managed_<AllocT> BOOST_MEMORY_CALL get_managed__(AllocT& alloc, destructor_t fn)
 {
- return _managed<AllocT>(alloc);
+ return managed_<AllocT>(alloc);
 }
 
 NS_BOOST_MEMORY_END
@@ -159,7 +159,7 @@
         ::new((alloc).unmanaged_alloc(sizeof(Type), BOOST_MEMORY_DESTRUCTOR(Type))) Type
 
 #define BOOST_MEMORY_GET_MANAGED_(alloc, Type) \
- NS_BOOST_MEMORY::_get_managed(alloc, BOOST_MEMORY_DESTRUCTOR(Type))
+ NS_BOOST_MEMORY::get_managed__(alloc, BOOST_MEMORY_DESTRUCTOR(Type))
 
 #define BOOST_MEMORY_NEW(alloc, Type) \
         BOOST_MEMORY_GET_MANAGED_(alloc, Type) ->* BOOST_MEMORY_UNMANAGED_ALLOC_(alloc, Type)
@@ -170,6 +170,7 @@
         ::new((alloc).allocate(sizeof(Type))) Type
 
 // =========================================================================
+// function enableMemoryLeakCheck
 
 NS_BOOST_MEMORY_BEGIN
 
@@ -182,6 +183,27 @@
 
 NS_BOOST_MEMORY_END
 
+// -------------------------------------------------------------------------
+// function swap_object
+
+NS_BOOST_MEMORY_BEGIN
+
+inline void swap(void* a, void* b, size_t cb)
+{
+ void* t = _alloca(cb);
+ memcpy(t, a, cb);
+ memcpy(a, b, cb);
+ memcpy(b, t, cb);
+}
+
+template <class Type>
+void swap_object(Type* a, Type* b)
+{
+ swap(a, b, sizeof(Type));
+}
+
+NS_BOOST_MEMORY_END
+
 // =========================================================================
 // $Log: basic.hpp,v $
 

Modified: sandbox/memory/boost/memory/container/dcl_list.hpp
==============================================================================
--- sandbox/memory/boost/memory/container/dcl_list.hpp (original)
+++ sandbox/memory/boost/memory/container/dcl_list.hpp 2009-04-23 07:29:02 EDT (Thu, 23 Apr 2009)
@@ -16,6 +16,10 @@
 #include "../basic.hpp"
 #endif
 
+#ifndef _ITERATOR_
+#include <iterator>
+#endif
+
 NS_BOOST_MEMORY_BEGIN
 
 // -------------------------------------------------------------------------

Modified: sandbox/memory/boost/memory/fixed_alloc.hpp
==============================================================================
--- sandbox/memory/boost/memory/fixed_alloc.hpp (original)
+++ sandbox/memory/boost/memory/fixed_alloc.hpp 2009-04-23 07:29:02 EDT (Thu, 23 Apr 2009)
@@ -40,6 +40,9 @@
 private:
         typedef typename PolicyT::alloc_type AllocT;
 
+ fixed_alloc(const fixed_alloc&);
+ void operator=(const fixed_alloc&);
+
 public:
         enum { MemBlockSize = PolicyT::MemBlockBytes - AllocT::Padding };
 
@@ -99,22 +102,37 @@
         {
                 init_(cbElem);
         }
-
         fixed_alloc(AllocT alloc, size_type cbElem)
                 : m_alloc(alloc)
         {
                 init_(cbElem);
         }
 
- fixed_alloc(fixed_alloc& owner, size_type cbElem)
- : m_alloc(owner.m_alloc)
+ ~fixed_alloc()
         {
- init_(cbElem);
+ clear();
         }
 
- ~fixed_alloc()
+ alloc_type BOOST_MEMORY_CALL get_alloc() const
         {
- clear();
+ return m_alloc;
+ }
+
+ void BOOST_MEMORY_CALL swap(fixed_alloc& o)
+ {
+ swap_object(this, &o);
+ }
+
+ void BOOST_MEMORY_CALL clear()
+ {
+ MemBlock* nextBlk;
+ for (MemBlock* blk = m_blks.first(); !m_blks.done(blk); blk = nextBlk)
+ {
+ nextBlk = blk->next();
+ m_alloc.deallocate(blk);
+ }
+ m_blks.clear();
+ m_freelist.clear();
         }
 
 private:
@@ -155,18 +173,6 @@
         }
 
 public:
- void BOOST_MEMORY_CALL clear()
- {
- MemBlock* nextBlk;
- for (MemBlock* blk = m_blks.first(); !m_blks.done(blk); blk = nextBlk)
- {
- nextBlk = blk->next();
- m_alloc.deallocate(blk);
- }
- m_blks.clear();
- m_freelist.clear();
- }
-
         __forceinline void* BOOST_MEMORY_CALL allocate()
         {
                 if (m_freelist.empty())

Modified: sandbox/memory/boost/memory/region_alloc.hpp
==============================================================================
--- sandbox/memory/boost/memory/region_alloc.hpp (original)
+++ sandbox/memory/boost/memory/region_alloc.hpp 2009-04-23 07:29:02 EDT (Thu, 23 Apr 2009)
@@ -16,10 +16,6 @@
 #include "basic.hpp"
 #endif
 
-#if !defined(_GLIBCXX_ALGORITHM) && !defined(_ALGORITHM)
-#include <algorithm> // std::swap
-#endif
-
 NS_BOOST_MEMORY_BEGIN
 
 // -------------------------------------------------------------------------
@@ -31,6 +27,9 @@
 private:
         typedef typename PolicyT::alloc_type AllocT;
 
+ region_alloc(const region_alloc&);
+ const region_alloc& operator=(const region_alloc&);
+
 public:
         enum { MemBlockSize = PolicyT::MemBlockBytes - AllocT::Padding };
 
@@ -59,8 +58,6 @@
         DestroyNode* m_destroyChain;
 
 private:
- const region_alloc& operator=(const region_alloc&);
-
         __forceinline MemBlock* BOOST_MEMORY_CALL chainHeader_() const
         {
                 return (MemBlock*)(m_begin - HeaderSize);
@@ -83,23 +80,20 @@
         {
                 init_();
         }
- explicit region_alloc(region_alloc& owner)
- : m_alloc(owner.m_alloc), m_destroyChain(NULL)
- {
- init_();
- }
 
         ~region_alloc()
         {
                 clear();
         }
 
+ alloc_type BOOST_MEMORY_CALL get_alloc() const
+ {
+ return m_alloc;
+ }
+
         void BOOST_MEMORY_CALL swap(region_alloc& o)
         {
- std::swap(m_begin, o.m_begin);
- std::swap(m_end, o.m_end);
- std::swap(m_destroyChain, o.m_destroyChain);
- m_alloc.swap(o.m_alloc);
+ swap_object(this, &o);
         }
 
         void BOOST_MEMORY_CALL clear()

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 2009-04-23 07:29:02 EDT (Thu, 23 Apr 2009)
@@ -21,6 +21,7 @@
 {
         int i;
         boost::memory::pool alloc(sizeof(int));
+ boost::memory::pool alloc2(sizeof(double));
 
         void* p[3000];
         for (i = 0; i < countof(p); ++i)
@@ -48,6 +49,7 @@
         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));
 
         void* p[3000];
         for (i = 0; i < countof(p); ++i)

Modified: sandbox/memory/libs/memory/examples/simplest/simple_examples.cpp
==============================================================================
--- sandbox/memory/libs/memory/examples/simplest/simple_examples.cpp (original)
+++ sandbox/memory/libs/memory/examples/simplest/simple_examples.cpp 2009-04-23 07:29:02 EDT (Thu, 23 Apr 2009)
@@ -40,7 +40,7 @@
         int* intBuf = BOOST_MEMORY_ALLOC(alloc, int);
         int* intArrayBuf = BOOST_MEMORY_ALLOC_ARRAY(alloc, int, 100);
         
- NS_BOOST_MEMORY::scoped_alloc* suballoc = BOOST_MEMORY_NEW(alloc, NS_BOOST_MEMORY::scoped_alloc)(alloc);
+ NS_BOOST_MEMORY::scoped_alloc* suballoc = BOOST_MEMORY_NEW(alloc, NS_BOOST_MEMORY::scoped_alloc)(alloc.get_alloc());
 
         int* e = BOOST_MEMORY_NEW(*suballoc, int);
 }
@@ -48,7 +48,7 @@
 void testTlsScopedAlloc()
 {
         NS_BOOST_MEMORY::scoped_alloc alloc;
- // same as: NS_BOOST_MEMORY::scoped_alloc(boost::tls_block_pool::instance());
+ // same as: NS_BOOST_MEMORY::scoped_alloc(boost::memory::tls_block_pool::instance());
         
         int* intObj = BOOST_MEMORY_NEW(alloc, int);
         int* intObjWithArg = BOOST_MEMORY_NEW(alloc, int)(10);


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