|
Boost-Commit : |
From: xushiweizh_at_[hidden]
Date: 2008-07-19 01:09:09
Author: xushiwei
Date: 2008-07-19 01:09:08 EDT (Sat, 19 Jul 2008)
New Revision: 47584
URL: http://svn.boost.org/trac/boost/changeset/47584
Log:
issue #94: defragment
Text files modified:
sandbox/memory/boost/memory.hpp | 48 +++++++++++++++++++++++++++++++++------
sandbox/memory/libs/memory/test/test_basic/memory/performance.cpp | 7 +++--
sandbox/memory/libs/memory/test/test_basic/memory/simple_examples.cpp | 2
3 files changed, 45 insertions(+), 12 deletions(-)
Modified: sandbox/memory/boost/memory.hpp
==============================================================================
--- sandbox/memory/boost/memory.hpp (original)
+++ sandbox/memory/boost/memory.hpp 2008-07-19 01:09:08 EDT (Sat, 19 Jul 2008)
@@ -49,6 +49,42 @@
#endif
// -------------------------------------------------------------------------
+// class defragment
+
+NS_BOOST_MEMORY_BEGIN
+
+template <class ContainerT>
+class defragment :
+ private ContainerT::alloc_type,
+ public ContainerT
+{
+public:
+ typedef typename ContainerT::alloc_type alloc_type;
+
+ alloc_type& BOOST_MEMORY_CALL get_alloc() {
+ return *static_cast<alloc_type*>(this);
+ }
+
+ void BOOST_MEMORY_CALL swap(defragment& o) {
+ ContainerT::swap(o);
+ alloc_type::swap(o.get_alloc());
+ }
+
+ void BOOST_MEMORY_CALL defrag() {
+ defragment o;
+ o.copy(*this);
+ swap(o);
+ }
+
+public:
+ defragment()
+ : ContainerT(get_alloc()) {
+ }
+};
+
+NS_BOOST_MEMORY_END
+
+// -------------------------------------------------------------------------
// class stl_allocator
NS_BOOST_MEMORY_BEGIN
@@ -103,7 +139,9 @@
public:
typedef AllocT alloc_type;
- AllocT& get_alloc() const { return *m_alloc; }
+ AllocT& BOOST_MEMORY_CALL get_alloc() const {
+ return *m_alloc;
+ }
};
#if !defined(BOOST_MEMORY_NO_PARTIAL_SPECIAILIZATION)
@@ -175,13 +213,6 @@
namespace boost
{
- namespace memory {}
-
- using NS_BOOST_MEMORY::system_alloc;
-
- using NS_BOOST_MEMORY::block_pool;
- using NS_BOOST_MEMORY::tls_block_pool;
-
using NS_BOOST_MEMORY::auto_alloc;
using NS_BOOST_MEMORY::scoped_alloc;
using NS_BOOST_MEMORY::gc_alloc;
@@ -204,3 +235,4 @@
// $Log: memory.hpp,v $
#endif /* BOOST_MEMORY_HPP */
+
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-07-19 01:09:08 EDT (Sat, 19 Jul 2008)
@@ -151,7 +151,7 @@
template <class LogT2>
void doScopedAlloc(LogT2& log, int NAlloc, int PerAlloc)
{
- NS_BOOST_MEMORY::block_pool& recycle = boost::tls_block_pool::instance();
+ NS_BOOST_MEMORY::block_pool& recycle = NS_BOOST_MEMORY::tls_block_pool::instance();
NS_BOOST_DETAIL::performance_counter counter;
{
for (int j = 0; j < NAlloc; ++j)
@@ -169,7 +169,7 @@
template <class LogT2>
void doGcAlloc(LogT2& log, int NAlloc, int PerAlloc)
{
- NS_BOOST_MEMORY::block_pool& recycle = boost::tls_block_pool::instance();
+ NS_BOOST_MEMORY::block_pool& recycle = NS_BOOST_MEMORY::tls_block_pool::instance();
NS_BOOST_DETAIL::performance_counter counter;
{
for (int j = 0; j < NAlloc; ++j)
@@ -189,7 +189,7 @@
const int PerAlloc1 = PerAlloc/2;
const int PerAlloc2 = PerAlloc - PerAlloc1;
int i;
- NS_BOOST_MEMORY::block_pool& recycle = boost::tls_block_pool::instance();
+ NS_BOOST_MEMORY::block_pool& recycle = NS_BOOST_MEMORY::tls_block_pool::instance();
NS_BOOST_DETAIL::performance_counter counter;
{
for (int j = 0; j < NAlloc; ++j)
@@ -300,3 +300,4 @@
// -------------------------------------------------------------------------
// $Log: performance.cpp,v $
//
+
Modified: sandbox/memory/libs/memory/test/test_basic/memory/simple_examples.cpp
==============================================================================
--- sandbox/memory/libs/memory/test/test_basic/memory/simple_examples.cpp (original)
+++ sandbox/memory/libs/memory/test/test_basic/memory/simple_examples.cpp 2008-07-19 01:09:08 EDT (Sat, 19 Jul 2008)
@@ -30,7 +30,7 @@
void testScopedAlloc()
{
- boost::block_pool recycle;
+ NS_BOOST_MEMORY::block_pool recycle;
boost::scoped_alloc alloc(recycle);
int* intObj = BOOST_NEW(alloc, int);
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