Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r65434 - sandbox/memory/boost/memory
From: xushiweizh_at_[hidden]
Date: 2010-09-16 03:26:05


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

Log:
1. windows 64bits -- to do
2. class MemoryState;
Text files modified:
   sandbox/memory/boost/memory/basic.hpp | 53 ++++++++++++++++++++++++++++++++++++++++
   sandbox/memory/boost/memory/pool_alloc.hpp | 6 ++++
   sandbox/memory/boost/memory/pools.hpp | 8 ++++-
   3 files changed, 65 insertions(+), 2 deletions(-)

Modified: sandbox/memory/boost/memory/basic.hpp
==============================================================================
--- sandbox/memory/boost/memory/basic.hpp (original)
+++ sandbox/memory/boost/memory/basic.hpp 2010-09-16 03:26:03 EDT (Thu, 16 Sep 2010)
@@ -252,8 +252,61 @@
 // =========================================================================
 // function enableMemoryLeakCheck
 
+#if !defined(_MAP_) || defined(_MAP)
+#include <map>
+#endif
+
 NS_BOOST_MEMORY_BEGIN
 
+class DbgMemoryState
+{
+private:
+ typedef std::pair<const char*, int> FileLine;
+ typedef std::map<void*, FileLine> Container;
+
+ Container m_data;
+
+public:
+ void BOOST_MEMORY_CALL allocate(void* p, const char* file = NULL, int line = 0)
+ {
+ BOOST_MEMORY_ASSERT(m_data.count(p) == 0);
+ const Container::value_type v = Container::value_type(p, FileLine(file, line));
+ m_data.insert(v);
+ }
+
+ void BOOST_MEMORY_CALL deallocate(void* p)
+ {
+ const Container::iterator it = m_data.find(p);
+ BOOST_MEMORY_ASSERT(it != m_data.end() && !"deallocate memory twice!");
+ m_data.erase(it);
+ }
+
+ void BOOST_MEMORY_CALL clear()
+ {
+ m_data.clear();
+ }
+
+ void BOOST_MEMORY_CALL reportMemoryLeak()
+ {
+ // todo;
+ }
+};
+
+class FakeMemoryState
+{
+public:
+ void BOOST_MEMORY_CALL allocate(void* p, const char* file = NULL, int line = 0) {}
+ void BOOST_MEMORY_CALL deallocate(void* p) {}
+ void BOOST_MEMORY_CALL clear() {}
+ void BOOST_MEMORY_CALL reportMemoryLeak() {}
+};
+
+#if defined(_DEBUG)
+typedef DbgMemoryState MemoryState;
+#else
+typedef FakeMemoryState MemoryState;
+#endif
+
 inline void BOOST_MEMORY_CALL enableMemoryLeakCheck()
 {
 #if defined(_MSC_VER)

Modified: sandbox/memory/boost/memory/pool_alloc.hpp
==============================================================================
--- sandbox/memory/boost/memory/pool_alloc.hpp (original)
+++ sandbox/memory/boost/memory/pool_alloc.hpp 2010-09-16 03:26:03 EDT (Thu, 16 Sep 2010)
@@ -70,6 +70,7 @@
         size_type m_cbChunk;
         size_type m_nChunkPerBlock;
         alloc_type m_alloc;
+ MemoryState m_mstate;
         BOOST_MEMORY_THREAD_CHECKER;
 
 private:
@@ -122,6 +123,7 @@
                 }
                 m_blks = NULL;
                 m_freelist = NULL;
+ m_mstate.clear();
         }
 
 private:
@@ -142,6 +144,7 @@
                 m_freelist = p->pPrev;
 
                 BOOST_MEMORY_DBG_FILL(p, alloc_size());
+ m_mstate.allocate(p);
                 return p;
         }
 
@@ -154,6 +157,7 @@
                         FreeChunk* p = m_freelist;
                         m_freelist = p->pPrev;
                         BOOST_MEMORY_DBG_FILL(p, alloc_size());
+ m_mstate.allocate(p);
                         return p;
                 }
                 return do_allocate_();
@@ -170,6 +174,7 @@
         {
                 BOOST_MEMORY_DBG_FILL(p, alloc_size());
                 BOOST_MEMORY_CHECK_THREAD();
+ m_mstate.deallocate(p);
 
                 ((FreeChunk*)p)->pPrev = m_freelist;
                 m_freelist = (FreeChunk*)p;
@@ -180,6 +185,7 @@
                 BOOST_MEMORY_ASSERT(cb <= alloc_size());
                 BOOST_MEMORY_DBG_FILL(p, alloc_size());
                 BOOST_MEMORY_CHECK_THREAD();
+ m_mstate.deallocate(p);
 
                 ((FreeChunk*)p)->pPrev = m_freelist;
                 m_freelist = (FreeChunk*)p;

Modified: sandbox/memory/boost/memory/pools.hpp
==============================================================================
--- sandbox/memory/boost/memory/pools.hpp (original)
+++ sandbox/memory/boost/memory/pools.hpp 2010-09-16 03:26:03 EDT (Thu, 16 Sep 2010)
@@ -23,7 +23,7 @@
 
 namespace detail {
 
-#if defined(_MSC_VER) // vc++
+#if defined(_MSC_VER) && defined(_M_IX86) // vc++, x86
 
 #if _MSC_VER > 1200
 #pragma warning(push)
@@ -43,6 +43,10 @@
 #pragma warning(pop)
 #endif
 
+#elif (0) // defined(_MSC_VER) && defined(_M_X64) // vc++, x64
+
+//
+
 #elif defined(__GNUG__) || defined(__GNUC__) // g++/gcc
 
 __forceinline unsigned int log2(unsigned int val)
@@ -73,7 +77,7 @@
         }
 }
 
-#pragma message("Warning: unknown compiler and use a slow log2 algorithm!"
+#pragma message("Warning: unknown compiler and use a slow log2 algorithm!")
 
 #endif
 


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