Boost logo

Boost-Commit :

From: xushiweizh_at_[hidden]
Date: 2008-05-07 05:32:58


Author: xushiwei
Date: 2008-05-07 05:32:57 EDT (Wed, 07 May 2008)
New Revision: 45192
URL: http://svn.boost.org/trac/boost/changeset/45192

Log:
1. BOOST_MEMORY_NO_STRICT_EXCEPTION_SEMANTICS.
2. gc_alloc defect: Segment fault in 64bits platform.

Text files modified:
   sandbox/memory/boost/memory/auto_alloc.hpp | 11 +++++++++
   sandbox/memory/boost/memory/basic.hpp | 35 +++++++++++++++++++++++++++++--
   sandbox/memory/boost/memory/gc_alloc.hpp | 43 ++++++++++++++++++++++++++++++---------
   sandbox/memory/libs/memory/test/test_basic/memory/performance.cpp | 34 ++++++++++++-------------------
   sandbox/memory/libs/memory/test/test_basic/test.cpp | 4 +-
   5 files changed, 90 insertions(+), 37 deletions(-)

Modified: sandbox/memory/boost/memory/auto_alloc.hpp
==============================================================================
--- sandbox/memory/boost/memory/auto_alloc.hpp (original)
+++ sandbox/memory/boost/memory/auto_alloc.hpp 2008-05-07 05:32:57 EDT (Wed, 07 May 2008)
@@ -175,9 +175,18 @@
                 return m_end -= cb;
         }
 
+ void* BOOST_MEMORY_CALL allocate(size_t cb, int fnZero)
+ {
+ return allocate(cb);
+ }
+
         void* BOOST_MEMORY_CALL allocate(size_t cb, destructor_t fn)
         {
- return manage(unmanaged_alloc(cb, fn), fn);
+ DestroyNode* pNode = (DestroyNode*)allocate(sizeof(DestroyNode) + cb);
+ pNode->fnDestroy = fn;
+ pNode->pPrev = m_destroyChain;
+ m_destroyChain = pNode;
+ return pNode + 1;
         }
 
         void* BOOST_MEMORY_CALL unmanaged_alloc(size_t cb, destructor_t fn)

Modified: sandbox/memory/boost/memory/basic.hpp
==============================================================================
--- sandbox/memory/boost/memory/basic.hpp (original)
+++ sandbox/memory/boost/memory/basic.hpp 2008-05-07 05:32:57 EDT (Wed, 07 May 2008)
@@ -311,7 +311,7 @@
 #define BOOST_MEMORY_FILE_LINE_ARG
 #endif
 
-#define BOOST_MEMORY_UNMANAGE_NEW(alloc, Type) \
+#define BOOST_MEMORY_UNMANAGED_NEW(alloc, Type) \
         ::new((alloc), (Type*)0, NS_BOOST_MEMORY::_theAllocFlag BOOST_MEMORY_FILE_LINE_ARG) Type
 
 // =========================================================================
@@ -335,12 +335,28 @@
         }
 };
 
+class _unmanaged
+{
+public:
+ template <class Type>
+ __forceinline Type* BOOST_MEMORY_CALL operator->*(Type* p) const
+ {
+ return p;
+ }
+};
+
 template <class AllocT>
-__forceinline _managed<AllocT> BOOST_MEMORY_CALL _get_managed(AllocT& alloc)
+__forceinline _managed<AllocT> BOOST_MEMORY_CALL _get_managed(AllocT& alloc, destructor_t fn)
 {
         return _managed<AllocT>(alloc);
 }
 
+template <class AllocT>
+__forceinline _unmanaged BOOST_MEMORY_CALL _get_managed(AllocT& alloc, int fnZero)
+{
+ return _unmanaged();
+}
+
 NS_BOOST_MEMORY_END
 
 #define BOOST_MEMORY_NEW_ARG(Type) sizeof(Type), NS_BOOST_MEMORY::destructor_traits<Type>::destruct
@@ -350,7 +366,20 @@
 #define BOOST_MEMORY_DBG_ALLOC_ARG(Type) sizeof(Type) BOOST_MEMORY_FILE_LINE_ARG
 #define BOOST_MEMORY_DBG_ALLOC_ARRAY_ARG(Type, count) sizeof(Type)*(count) BOOST_MEMORY_FILE_LINE_ARG
 
-#define BOOST_MEMORY_NEW(alloc, Type) NS_BOOST_MEMORY::_get_managed(alloc) ->* BOOST_MEMORY_UNMANAGE_NEW(alloc, Type)
+#if defined(BOOST_MEMORY_NO_STRICT_EXCEPTION_SEMANTICS)
+//
+// Backard options:
+// not strict in accord with normal C++ semantics but a bit faster
+//
+#define BOOST_MEMORY_NEW(alloc, Type) \
+ ::new((alloc).allocate(BOOST_MEMORY_DBG_NEW_ARG(Type))) Type
+#else
+#define BOOST_MEMORY_GET_MANAGED_(alloc, Type) \
+ NS_BOOST_MEMORY::_get_managed(alloc, NS_BOOST_MEMORY::destructor_traits<Type>::destruct)
+#define BOOST_MEMORY_NEW(alloc, Type) \
+ BOOST_MEMORY_GET_MANAGED_(alloc, Type) ->* BOOST_MEMORY_UNMANAGED_NEW(alloc, Type)
+#endif
+
 #define BOOST_MEMORY_NEW_ARRAY(alloc, Type, count) (alloc).newArray(BOOST_MEMORY_DBG_NEW_ARRAY_ARG(Type, count))
 
 #define BOOST_MEMORY_ALLOC(alloc, Type) ((Type*)(alloc).allocate(BOOST_MEMORY_DBG_ALLOC_ARG(Type)))

Modified: sandbox/memory/boost/memory/gc_alloc.hpp
==============================================================================
--- sandbox/memory/boost/memory/gc_alloc.hpp (original)
+++ sandbox/memory/boost/memory/gc_alloc.hpp 2008-05-07 05:32:57 EDT (Wed, 07 May 2008)
@@ -456,7 +456,17 @@
                 if (cbAlloc >= AllocSizeHuge)
                         return m_hugeAlloc.allocate(cb, fn);
                 
- return manage(unmanaged_alloc(cb, fn), fn);
+ DestroyInfo* pNode = (DestroyInfo*)allocate(sizeof(DestroyInfo) + cb);
+ pNode->fnDestroy = fn;
+ pNode->pPrev = m_destroyChain;
+ m_destroyChain = (MemHeaderEx*)((char*)pNode - sizeof(MemHeader));
+ m_destroyChain->nodeType = nodeAllocedWithDestructor;
+ return pNode + 1;
+ }
+
+ void* BOOST_MEMORY_CALL allocate(size_t cb, int fnZero)
+ {
+ return allocate(cb);
         }
 
         void* BOOST_MEMORY_CALL unmanaged_alloc(size_t cb, destructor_t fn)
@@ -492,6 +502,7 @@
         void BOOST_MEMORY_CALL deallocate(void* pData, size_t cbData)
         {
                 const size_t cb = cbData + sizeof(MemHeader);
+
                 if (cb >= AllocSizeHuge)
                 {
                         m_hugeAlloc.deallocate(pData, cbData);
@@ -502,7 +513,7 @@
                         BOOST_MEMORY_ASSERT(p->cbNodeSize == cb);
                         BOOST_MEMORY_ASSERT(p->nodeType == nodeAlloced);
 
- p->nodeType = nodeFree;
+ ((FreeMemHeader*)p)->cbNodeSize = cb;
                         m_freeSize += cb;
                 }
         }
@@ -519,19 +530,25 @@
         template <class Type>
         void BOOST_MEMORY_CALL _destroy(Type* obj, destructor_t)
         {
+ const size_t cb = sizeof(Type) + sizeof(MemHeaderEx);
+
                 obj->~Type();
                 MemHeaderEx* p = (MemHeaderEx*)obj - 1;
- p->nodeType = nodeFree;
- m_freeSize += sizeof(Type) + sizeof(MemHeaderEx);
+
+ ((FreeMemHeader*)p)->cbNodeSize = cb;
+ m_freeSize += cb;
                 ++m_destroyCount;
         }
 
         template <class Type>
         void BOOST_MEMORY_CALL _destroy(Type* obj, int)
         {
+ const size_t cb = sizeof(Type) + sizeof(MemHeader);
+
                 MemHeader* p = (MemHeader*)obj - 1;
- p->nodeType = nodeFree;
- m_freeSize += sizeof(Type) + sizeof(MemHeader);
+
+ ((FreeMemHeader*)p)->cbNodeSize = cb;
+ m_freeSize += cb;
         }
 
         template <class Type>
@@ -539,20 +556,26 @@
         {
                 typedef destructor_traits<Type> Traits;
 
+ const size_t cb = Traits::getArrayAllocSize(count) + sizeof(MemHeaderEx);
+
                 Traits::destructArrayN(array, count);
                 void* pData = Traits::getArrayBuffer(array);
                 MemHeaderEx* p = (MemHeaderEx*)pData - 1;
- p->nodeType = nodeFree;
- m_freeSize += Traits::getArrayAllocSize(count) + sizeof(MemHeaderEx);
+
+ ((FreeMemHeader*)p)->cbNodeSize = cb;
+ m_freeSize += cb;
                 ++m_destroyCount;
         }
 
         template <class Type>
         void BOOST_MEMORY_CALL _destroyArray(Type* array, size_t count, int)
         {
+ const size_t cb = sizeof(Type) * count + sizeof(MemHeader);
+
                 MemHeader* p = (MemHeader*)array - 1;
- p->nodeType = nodeFree;
- m_freeSize += sizeof(Type) * count + sizeof(MemHeader);
+
+ ((FreeMemHeader*)p)->cbNodeSize = cb;
+ m_freeSize += cb;
         }
 
 public:

Modified: sandbox/memory/libs/memory/test/test_basic/memory/performance.cpp
==============================================================================
--- sandbox/memory/libs/memory/test/test_basic/memory/performance.cpp (original)
+++ sandbox/memory/libs/memory/test/test_basic/memory/performance.cpp 2008-05-07 05:32:57 EDT (Wed, 07 May 2008)
@@ -21,24 +21,18 @@
 
 // -------------------------------------------------------------------------
 
+enum { Total = 1000000 };
+
+static int* p[Total];
+
 template <class LogT>
 class TestAllocatorPerformance
 {
 private:
- enum { Total = 1000000 };
-
         NS_BOOST_DETAIL::accumulator m_acc;
         NS_BOOST_MEMORY::block_pool m_recycle;
- int** p;
 
 public:
- TestAllocatorPerformance() {
- p = new int*[Total];
- }
- ~TestAllocatorPerformance() {
- delete[] p;
- }
-
         void doNewDelete(LogT& log, int NAlloc, int PerAlloc)
         {
                 int i;
@@ -66,8 +60,7 @@
                 typedef __gnu_cxx::__pool_base::_Tune tune_type;
                 //tune_type tune(16, 5120, 32, 5120, 20, 10, false);
                 
- int i, **p;
- p = new int*[PerAlloc];
+ int i;
                 NS_BOOST_DETAIL::performance_counter counter;
                 {
                         for (int j = 0; j < NAlloc; ++j)
@@ -85,7 +78,6 @@
                         }
                 }
                 m_acc.accumulate(counter.trace(log));
- delete[] p;
         }
 #endif
 
@@ -246,14 +238,6 @@
                         doGcAllocManually(log, NAlloc, PerAlloc);
                 m_acc.trace_avg(log);
 
-#if defined(__GNUG__)
- m_acc.start();
- log.trace("\n===== MtAllocator(%d) =====\n", PerAlloc);
- for (i = 0; i < Count; ++i)
- doMtAllocator(log, NAlloc, PerAlloc);
- m_acc.trace_avg(log);
-#endif
-
                 m_acc.start();
                 log.trace("\n===== BoostPool(%d) =====\n", PerAlloc);
                 for (i = 0; i < Count; ++i)
@@ -266,6 +250,14 @@
                         doBoostObjectPool(log, NAlloc, PerAlloc);
                 m_acc.trace_avg(log);
 
+#if defined(__GNUG__)
+ m_acc.start();
+ log.trace("\n===== MtAllocator(%d) =====\n", PerAlloc);
+ for (i = 0; i < Count; ++i)
+ doMtAllocator(log, NAlloc, PerAlloc);
+ m_acc.trace_avg(log);
+#endif
+
                 m_acc.start();
                 log.trace("\n===== NewDelete(%d) =====\n", PerAlloc);
                 for (i = 0; i < Count; ++i)

Modified: sandbox/memory/libs/memory/test/test_basic/test.cpp
==============================================================================
--- sandbox/memory/libs/memory/test/test_basic/test.cpp (original)
+++ sandbox/memory/libs/memory/test/test_basic/test.cpp 2008-05-07 05:32:57 EDT (Wed, 07 May 2008)
@@ -21,8 +21,8 @@
 
 int main()
 {
-// testPerformance();
- testExceptionSemantics();
+ testPerformance();
+// testExceptionSemantics();
 // testSystemAlloc();
 // testPerformance();
 // simpleExamples();


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