|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r52676 - in sandbox/memory: boost/memory boost/memory/container libs/memory/examples/pool
From: xushiweizh_at_[hidden]
Date: 2009-04-30 05:59:58
Author: xushiwei
Date: 2009-04-30 05:59:57 EDT (Thu, 30 Apr 2009)
New Revision: 52676
URL: http://svn.boost.org/trac/boost/changeset/52676
Log:
issue #108 (http://code.google.com/p/winx/issues/detail?id=108):
bug fix: Sometimes fixed_alloc::deallocate access violation.
Text files modified:
sandbox/memory/boost/memory/container/dcl_list.hpp | 6 ++++++
sandbox/memory/boost/memory/fixed_alloc.hpp | 10 +++++-----
sandbox/memory/libs/memory/examples/pool/simple_examples.cpp | 11 ++++++++---
3 files changed, 19 insertions(+), 8 deletions(-)
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-30 05:59:57 EDT (Thu, 30 Apr 2009)
@@ -81,6 +81,11 @@
return m_next == this;
}
+ bool BOOST_MEMORY_CALL valid() const
+ {
+ return m_prev->m_next == this && m_next->m_prev == this;
+ }
+
void BOOST_MEMORY_CALL clear()
{
m_next = m_prev = this;
@@ -88,6 +93,7 @@
void BOOST_MEMORY_CALL erase()
{
+ BOOST_MEMORY_ASSERT(valid());
m_next->m_prev = m_prev;
m_prev->m_next = m_next;
m_prev = m_next = this;
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-30 05:59:57 EDT (Thu, 30 Apr 2009)
@@ -188,12 +188,12 @@
__forceinline void BOOST_MEMORY_CALL deallocate(void* const p)
{
- BOOST_MEMORY_ASSERT(chunkHeader_(p)->nUsed <= m_nMaxPerBlock);
-
MemBlock* const blk = chunkHeader_(p);
- if (--blk->nUsed > 0)
- m_freelist.push_front((FreeChunk*)p);
- else if (blk != m_lastBlock)
+
+ BOOST_MEMORY_ASSERT(blk->nUsed > 0 && blk->nUsed <= m_nMaxPerBlock);
+
+ m_freelist.push_front((FreeChunk*)p);
+ if (--blk->nUsed == 0 && blk != m_lastBlock)
do_deallocate_block_(blk);
}
};
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-30 05:59:57 EDT (Thu, 30 Apr 2009)
@@ -23,11 +23,16 @@
boost::memory::pool alloc(sizeof(int));
boost::memory::pool alloc2(sizeof(double));
- void* p[3000];
+ int* p[3000];
for (i = 0; i < countof(p); ++i)
- p[i] = alloc.allocate();
+ {
+ p[i] = (int*)alloc.allocate();
+ *p[i] = i;
+ }
for (i = 0; i < countof(p); ++i)
+ {
alloc.deallocate(p[i]);
+ }
void* p1 = alloc.allocate();
void* p2 = alloc.allocate();
@@ -79,7 +84,7 @@
{
char m_val[100];
- Obj() { ++g_nConstruct; }
+ Obj() { ++g_nConstruct; m_val[1] = 0x23; }
Obj(int val) { ++g_nConstruct; }
~Obj() { ++g_nDestruct; }
};
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