Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r52343 - in sandbox/memory/boost: . memory
From: xushiweizh_at_[hidden]
Date: 2009-04-12 00:37:04


Author: xushiwei
Date: 2009-04-12 00:37:02 EDT (Sun, 12 Apr 2009)
New Revision: 52343
URL: http://svn.boost.org/trac/boost/changeset/52343

Log:
1. bugfix: stl_allocator
2. vc++ 6.0 spec: class auto_alloc
Text files modified:
   sandbox/memory/boost/memory.hpp | 43 ++++++++++++------
   sandbox/memory/boost/memory/auto_alloc.hpp | 92 +++++++++++++++++++++++++++++++++++----
   sandbox/memory/boost/memory/scoped_alloc.hpp | 77 +++++++++++++++++++++++++++++++++
   3 files changed, 186 insertions(+), 26 deletions(-)

Modified: sandbox/memory/boost/memory.hpp
==============================================================================
--- sandbox/memory/boost/memory.hpp (original)
+++ sandbox/memory/boost/memory.hpp 2009-04-12 00:37:02 EDT (Sun, 12 Apr 2009)
@@ -41,6 +41,19 @@
 #endif
 
 // -------------------------------------------------------------------------
+// default_alloc
+
+NS_BOOST_MEMORY_BEGIN
+
+#if defined(BOOST_MEMORY_USE_AUTO_ALLOC)
+typedef auto_alloc default_alloc;
+#else
+typedef scoped_alloc default_alloc;
+#endif
+
+NS_BOOST_MEMORY_END
+
+// -------------------------------------------------------------------------
 // function swap_object
 
 NS_BOOST_MEMORY_BEGIN
@@ -105,7 +118,7 @@
 
 NS_BOOST_MEMORY_BEGIN
 
-template <class Type, class AllocT = scoped_alloc>
+template <class Type, class AllocT = default_alloc>
 class stl_allocator
 {
 private:
@@ -170,12 +183,12 @@
 class stl_allocator<void, AllocT>
 {
 public:
- typedef void value_type;
- typedef void* pointer;
- typedef const void* const_pointer;
-
- template <class U>
- struct rebind { typedef stl_allocator<U, scoped_alloc> other; };
+ typedef void value_type;
+ typedef void* pointer;
+ typedef const void* const_pointer;
+
+ template <class U>
+ struct rebind { typedef stl_allocator<U, AllocT> other; };
 };
 
 #else
@@ -183,12 +196,12 @@
 template<> class stl_allocator<void, scoped_alloc>
 {
 public:
- typedef void value_type;
- typedef void* pointer;
- typedef const void* const_pointer;
-
- template <class U>
- struct rebind { typedef stl_allocator<U, scoped_alloc> other; };
+ typedef void value_type;
+ typedef void* pointer;
+ typedef const void* const_pointer;
+
+ template <class U>
+ struct rebind { typedef stl_allocator<U, scoped_alloc> other; };
 };
 
 template<> class stl_allocator<void, auto_alloc>
@@ -199,7 +212,7 @@
     typedef const void* const_pointer;
  
     template <class U>
- struct rebind { typedef stl_allocator<U, scoped_alloc> other; };
+ struct rebind { typedef stl_allocator<U, auto_alloc> other; };
 };
 
 /*
@@ -211,7 +224,7 @@
     typedef const void* const_pointer;
  
     template <class U>
- struct rebind { typedef stl_allocator<U, scoped_alloc> other; };
+ struct rebind { typedef stl_allocator<U, gc_alloc> other; };
 };
 */
 

Modified: sandbox/memory/boost/memory/auto_alloc.hpp
==============================================================================
--- sandbox/memory/boost/memory/auto_alloc.hpp (original)
+++ sandbox/memory/boost/memory/auto_alloc.hpp 2009-04-12 00:37:02 EDT (Sun, 12 Apr 2009)
@@ -66,12 +66,12 @@
 private:
         const region_alloc& operator=(const region_alloc&);
 
- MemBlock* BOOST_MEMORY_CALL _chainHeader() const
+ MemBlock* BOOST_MEMORY_CALL chainHeader_() const
         {
                 return (MemBlock*)(m_begin - HeaderSize);
         }
 
- void BOOST_MEMORY_CALL _init()
+ void BOOST_MEMORY_CALL init_()
         {
                 MemBlock* pNew = (MemBlock*)m_alloc.allocate(sizeof(MemBlock));
                 pNew->pPrev = NULL;
@@ -82,16 +82,16 @@
 public:
         region_alloc() : m_destroyChain(NULL)
         {
- _init();
+ init_();
         }
         explicit region_alloc(AllocT alloc) : m_alloc(alloc), m_destroyChain(NULL)
         {
- _init();
+ init_();
         }
         explicit region_alloc(region_alloc& owner)
                 : m_alloc(owner.m_alloc), m_destroyChain(NULL)
         {
- _init();
+ init_();
         }
 
         ~region_alloc()
@@ -115,7 +115,7 @@
                         m_destroyChain = m_destroyChain->pPrev;
                         curr->fnDestroy(curr + 1);
                 }
- MemBlock* pHeader = _chainHeader();
+ MemBlock* pHeader = chainHeader_();
                 while (pHeader)
                 {
                         MemBlock* curr = pHeader;
@@ -126,11 +126,11 @@
         }
 
 private:
- void* BOOST_MEMORY_CALL _do_allocate(size_t cb)
+ void* BOOST_MEMORY_CALL do_allocate_(size_t cb)
         {
                 if (cb >= BlockSize)
                 {
- MemBlock* pHeader = _chainHeader();
+ MemBlock* pHeader = chainHeader_();
                         MemBlock* pNew = (MemBlock*)m_alloc.allocate(HeaderSize + cb);
                         if (pHeader)
                         {
@@ -147,7 +147,7 @@
                 else
                 {
                         MemBlock* pNew = (MemBlock*)m_alloc.allocate(sizeof(MemBlock));
- pNew->pPrev = _chainHeader();
+ pNew->pPrev = chainHeader_();
                         m_begin = pNew->buffer;
                         m_end = (char*)pNew + m_alloc.alloc_size(pNew);
                         return m_end -= cb;
@@ -161,7 +161,7 @@
                 {
                         return m_end -= cb;
                 }
- return _do_allocate(cb);
+ return do_allocate_(cb);
         }
 
 #if defined(BOOST_MEMORY_NO_STRICT_EXCEPTION_SEMANTICS)
@@ -236,8 +236,80 @@
 // -------------------------------------------------------------------------
 // class auto_alloc
 
+#if defined(_MSC_VER) && (_MSC_VER <= 1200) // VC++ 6.0
+
+class auto_alloc
+{
+private:
+ region_alloc<NS_BOOST_MEMORY_POLICY::stdlib> m_impl;
+
+public:
+ auto_alloc() {}
+ explicit auto_alloc(auto_alloc&) {}
+
+ __forceinline void BOOST_MEMORY_CALL swap(auto_alloc& o) {
+ m_impl.swap(o.m_impl);
+ }
+
+ __forceinline void BOOST_MEMORY_CALL clear() {
+ m_impl.clear();
+ }
+
+ __forceinline void* BOOST_MEMORY_CALL allocate(size_t cb) {
+ return m_impl.allocate(cb);
+ }
+
+#if defined(BOOST_MEMORY_NO_STRICT_EXCEPTION_SEMANTICS)
+ __forceinline void* BOOST_MEMORY_CALL allocate(size_t cb, int fnZero) {
+ return m_impl.allocate(cb);
+ }
+
+ __forceinline void* BOOST_MEMORY_CALL allocate(size_t cb, destructor_t fn) {
+ return m_impl.allocate(cb, fn);
+ }
+#endif
+
+ __forceinline void* BOOST_MEMORY_CALL unmanaged_alloc(size_t cb, destructor_t fn) {
+ return m_impl.unmanaged_alloc(cb, fn);
+ }
+
+ __forceinline void BOOST_MEMORY_CALL manage(void* p, destructor_t fn) {
+ m_impl.manage(p, fn);
+ }
+
+ __forceinline void* BOOST_MEMORY_CALL unmanaged_alloc(size_t cb, int fnZero) {
+ return m_impl.allocate(cb);
+ }
+
+ __forceinline void BOOST_MEMORY_CALL manage(void* p, int fnZero) {
+ // no action
+ }
+
+ void* BOOST_MEMORY_CALL reallocate(void* p, size_t oldSize, size_t newSize) {
+ return m_impl.reallocate(p, oldSize, newSize);
+ }
+
+ void BOOST_MEMORY_CALL deallocate(void* p, size_t cb) {
+ // no action
+ }
+
+ template <class Type>
+ void BOOST_MEMORY_CALL destroy(Type* obj) {
+ // no action
+ }
+
+ template <class Type>
+ void BOOST_MEMORY_CALL destroyArray(Type* array, size_t count) {
+ // no action
+ }
+};
+
+#else
+
 typedef region_alloc<NS_BOOST_MEMORY_POLICY::stdlib> auto_alloc;
 
+#endif
+
 // -------------------------------------------------------------------------
 // $Log: auto_alloc.hpp,v $
 

Modified: sandbox/memory/boost/memory/scoped_alloc.hpp
==============================================================================
--- sandbox/memory/boost/memory/scoped_alloc.hpp (original)
+++ sandbox/memory/boost/memory/scoped_alloc.hpp 2009-04-12 00:37:02 EDT (Sun, 12 Apr 2009)
@@ -177,7 +177,7 @@
 typedef tls_block_pool_<int> tls_block_pool;
 
 // -------------------------------------------------------------------------
-// class scoped_alloc
+// class pool
 
 typedef proxy_alloc<block_pool, tls_block_pool> proxy_block_pool;
 
@@ -191,8 +191,83 @@
 
 NS_BOOST_MEMORY_POLICY_END
 
+// -------------------------------------------------------------------------
+// class scoped_alloc
+
+#if 0 // defined(_MSC_VER) && (_MSC_VER <= 1200) // VC++ 6.0
+
+class scoped_alloc
+{
+private:
+ region_alloc<NS_BOOST_MEMORY_POLICY::pool> m_impl;
+
+public:
+ scoped_alloc() {}
+ explicit scoped_alloc(scoped_alloc&) {}
+
+ __forceinline void BOOST_MEMORY_CALL swap(scoped_alloc& o) {
+ m_impl.swap(o.m_impl);
+ }
+
+ __forceinline void BOOST_MEMORY_CALL clear() {
+ m_impl.clear();
+ }
+
+ __forceinline void* BOOST_MEMORY_CALL allocate(size_t cb) {
+ return m_impl.allocate(cb);
+ }
+
+#if defined(BOOST_MEMORY_NO_STRICT_EXCEPTION_SEMANTICS)
+ __forceinline void* BOOST_MEMORY_CALL allocate(size_t cb, int fnZero) {
+ return m_impl.allocate(cb);
+ }
+
+ __forceinline void* BOOST_MEMORY_CALL allocate(size_t cb, destructor_t fn) {
+ return m_impl.allocate(cb, fn);
+ }
+#endif
+
+ __forceinline void* BOOST_MEMORY_CALL unmanaged_alloc(size_t cb, destructor_t fn) {
+ return m_impl.unmanaged_alloc(cb, fn);
+ }
+
+ __forceinline void BOOST_MEMORY_CALL manage(void* p, destructor_t fn) {
+ m_impl.manage(p, fn);
+ }
+
+ __forceinline void* BOOST_MEMORY_CALL unmanaged_alloc(size_t cb, int fnZero) {
+ return m_impl.allocate(cb);
+ }
+
+ __forceinline void BOOST_MEMORY_CALL manage(void* p, int fnZero) {
+ // no action
+ }
+
+ void* BOOST_MEMORY_CALL reallocate(void* p, size_t oldSize, size_t newSize) {
+ return m_impl.reallocate(p, oldSize, newSize);
+ }
+
+ void BOOST_MEMORY_CALL deallocate(void* p, size_t cb) {
+ // no action
+ }
+
+ template <class Type>
+ void BOOST_MEMORY_CALL destroy(Type* obj) {
+ // no action
+ }
+
+ template <class Type>
+ void BOOST_MEMORY_CALL destroyArray(Type* array, size_t count) {
+ // no action
+ }
+};
+
+#else
+
 typedef region_alloc<NS_BOOST_MEMORY_POLICY::pool> scoped_alloc;
 
+#endif
+
 // -------------------------------------------------------------------------
 // $Log: $
 


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