|
Boost-Commit : |
From: xushiweizh_at_[hidden]
Date: 2008-05-02 23:53:01
Author: xushiwei
Date: 2008-05-02 23:53:00 EDT (Fri, 02 May 2008)
New Revision: 45057
URL: http://svn.boost.org/trac/boost/changeset/45057
Log:
issue #1885: gc_alloc - change some implementation details.
Text files modified:
sandbox/memory/boost/memory/gc_alloc.hpp | 26 ++++++++++++++++++++++----
sandbox/memory/libs/memory/src/block_pool.cpp | 2 +-
2 files changed, 23 insertions(+), 5 deletions(-)
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-02 23:53:00 EDT (Fri, 02 May 2008)
@@ -31,6 +31,10 @@
// -------------------------------------------------------------------------
// class gen_alloc
+#ifdef _DEBUG
+#define BOOST_MEMORY_TRACE_GC
+#endif
+
#ifndef MAX
#define MAX(a, b) ((a) < (b) ? (b) : (a))
#endif
@@ -226,10 +230,13 @@
public:
void BOOST_MEMORY_CALL force_gc()
{
+#if defined(BOOST_MEMORY_TRACE_GC)
+ printf("boost::gc_alloc - starting to gc...\n");
+#endif
// 0. Prepare
// 0.1. Commit current block:
- _commitCurrentBlock();
+ _commitCurrentNode();
m_begin = m_end = _null.begin();
// 0.2. Reduce destroy chain
@@ -305,10 +312,13 @@
}
}
- void BOOST_MEMORY_CALL _commitCurrentBlock()
+ void BOOST_MEMORY_CALL _commitCurrentNode()
{
FreeMemHeader* pNode = (FreeMemHeader*)m_begin - 1;
- BOOST_MEMORY_ASSERT(pNode->getNodeType() == nodeFree);
+ BOOST_MEMORY_ASSERT(
+ pNode->getNodeType() == nodeFree ||
+ pNode->getNodeType() == nodeAlloced &&
+ _null.begin() == m_begin && m_begin == m_end);
pNode->cbNodeSize = sizeof(FreeMemHeader) + (m_end - m_begin);
}
@@ -395,6 +405,14 @@
const size_t cb = cbData + sizeof(MemHeader);
if ((size_t)(m_end - m_begin) < cb)
{
+ if ((size_t)(m_end - m_begin) >= cbData)
+ {
+ MemHeader* pAlloc = (MemHeader*)m_begin - 1;
+ pAlloc->nodeType = nodeAlloced;
+ pAlloc->cbNodeSize = m_end - (char*)pAlloc;
+ m_begin = m_end = _null.begin();
+ return pAlloc + 1;
+ }
FreeMemHeader* pNew;
if (cb >= AllocSizeBig)
{
@@ -419,7 +437,7 @@
m_freeList.pop();
}
}
- _commitCurrentBlock();
+ _commitCurrentNode();
m_begin = pNew->begin();
m_end = pNew->end();
}
Modified: sandbox/memory/libs/memory/src/block_pool.cpp
==============================================================================
--- sandbox/memory/libs/memory/src/block_pool.cpp (original)
+++ sandbox/memory/libs/memory/src/block_pool.cpp 2008-05-02 23:53:00 EDT (Fri, 02 May 2008)
@@ -14,7 +14,7 @@
// -------------------------------------------------------------------------
-using namespace boost;
+using namespace NS_BOOST_MEMORY;
tls_block_pool_t g_tls_blockPool;
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