Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r57661 - in sandbox/memory/boost: . memory memory/container
From: xushiweizh_at_[hidden]
Date: 2009-11-14 15:17:56


Author: xushiwei
Date: 2009-11-14 15:17:54 EST (Sat, 14 Nov 2009)
New Revision: 57661
URL: http://svn.boost.org/trac/boost/changeset/57661

Log:
1. boost/memory/pool_alloc.hpp
2. boost/memory/pools.hpp
Text files modified:
   sandbox/memory/boost/memory.hpp | 4 -
   sandbox/memory/boost/memory/auto_alloc.hpp | 1
   sandbox/memory/boost/memory/basic.hpp | 1
   sandbox/memory/boost/memory/block_pool.hpp | 1
   sandbox/memory/boost/memory/container/dcl_list.hpp | 1
   sandbox/memory/boost/memory/fixed_alloc.hpp | 1
   sandbox/memory/boost/memory/object_pool.hpp | 1
   sandbox/memory/boost/memory/pool.hpp | 9 +-
   sandbox/memory/boost/memory/pool_alloc.hpp | 137 +++++++++++++++------------------------
   sandbox/memory/boost/memory/pools.hpp | 14 ++--
   sandbox/memory/boost/memory/region_alloc.hpp | 1
   sandbox/memory/boost/memory/scoped_alloc.hpp | 1
   sandbox/memory/boost/memory/system_alloc.hpp | 5
   sandbox/memory/boost/memory/type_traits.hpp | 1
   14 files changed, 66 insertions(+), 112 deletions(-)

Modified: sandbox/memory/boost/memory.hpp
==============================================================================
--- sandbox/memory/boost/memory.hpp (original)
+++ sandbox/memory/boost/memory.hpp 2009-11-14 15:17:54 EST (Sat, 14 Nov 2009)
@@ -34,10 +34,6 @@
 #include "memory/pools.hpp"
 #endif
 
-#ifndef BOOST_MEMORY_OBJECT_POOL_HPP
-#include "memory/object_pool.hpp"
-#endif
-
 // -------------------------------------------------------------------------
 // default_alloc
 

Modified: sandbox/memory/boost/memory/auto_alloc.hpp
==============================================================================
--- sandbox/memory/boost/memory/auto_alloc.hpp (original)
+++ sandbox/memory/boost/memory/auto_alloc.hpp 2009-11-14 15:17:54 EST (Sat, 14 Nov 2009)
@@ -105,7 +105,6 @@
 #endif
 
 // -------------------------------------------------------------------------
-// $Log: auto_alloc.hpp,v $
 
 NS_BOOST_MEMORY_END
 

Modified: sandbox/memory/boost/memory/basic.hpp
==============================================================================
--- sandbox/memory/boost/memory/basic.hpp (original)
+++ sandbox/memory/boost/memory/basic.hpp 2009-11-14 15:17:54 EST (Sat, 14 Nov 2009)
@@ -226,6 +226,5 @@
 NS_BOOST_MEMORY_END
 
 // =========================================================================
-// $Log: basic.hpp,v $
 
 #endif /* BOOST_MEMORY_BASIC_HPP */

Modified: sandbox/memory/boost/memory/block_pool.hpp
==============================================================================
--- sandbox/memory/boost/memory/block_pool.hpp (original)
+++ sandbox/memory/boost/memory/block_pool.hpp 2009-11-14 15:17:54 EST (Sat, 14 Nov 2009)
@@ -168,7 +168,6 @@
 NS_BOOST_MEMORY_POLICY_END
 
 // -------------------------------------------------------------------------
-// $Log: $
 
 NS_BOOST_MEMORY_END
 

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-11-14 15:17:54 EST (Sat, 14 Nov 2009)
@@ -251,7 +251,6 @@
 };
 
 // -------------------------------------------------------------------------
-// $Log: $
 
 NS_BOOST_MEMORY_END
 

Modified: sandbox/memory/boost/memory/fixed_alloc.hpp
==============================================================================
--- sandbox/memory/boost/memory/fixed_alloc.hpp (original)
+++ sandbox/memory/boost/memory/fixed_alloc.hpp 2009-11-14 15:17:54 EST (Sat, 14 Nov 2009)
@@ -223,7 +223,6 @@
 #pragma pack()
 
 // -------------------------------------------------------------------------
-// $Log: $
 
 NS_BOOST_MEMORY_END
 

Modified: sandbox/memory/boost/memory/object_pool.hpp
==============================================================================
--- sandbox/memory/boost/memory/object_pool.hpp (original)
+++ sandbox/memory/boost/memory/object_pool.hpp 2009-11-14 15:17:54 EST (Sat, 14 Nov 2009)
@@ -295,7 +295,6 @@
 };
 
 // -------------------------------------------------------------------------
-// $Log: $
 
 NS_BOOST_MEMORY_END
 

Modified: sandbox/memory/boost/memory/pool.hpp
==============================================================================
--- sandbox/memory/boost/memory/pool.hpp (original)
+++ sandbox/memory/boost/memory/pool.hpp 2009-11-14 15:17:54 EST (Sat, 14 Nov 2009)
@@ -12,8 +12,8 @@
 #ifndef BOOST_MEMORY_POOL_HPP
 #define BOOST_MEMORY_POOL_HPP
 
-#ifndef BOOST_MEMORY_FIXED_ALLOC_HPP
-#include "fixed_alloc.hpp"
+#ifndef BOOST_MEMORY_POOL_ALLOC_HPP
+#include "pool_alloc.hpp"
 #endif
 
 #ifndef BOOST_MEMORY_BLOCKPOOL_HPP
@@ -25,11 +25,10 @@
 // -------------------------------------------------------------------------
 // class pool, scoped_pool
 
-typedef fixed_alloc<NS_BOOST_MEMORY_POLICY::stdlib> pool;
-typedef fixed_alloc<NS_BOOST_MEMORY_POLICY::scoped> scoped_pool;
+typedef pool_alloc<NS_BOOST_MEMORY_POLICY::stdlib> pool;
+typedef pool_alloc<NS_BOOST_MEMORY_POLICY::scoped> scoped_pool;
 
 // -------------------------------------------------------------------------
-// $Log: $
 
 NS_BOOST_MEMORY_END
 

Modified: sandbox/memory/boost/memory/pool_alloc.hpp
==============================================================================
--- sandbox/memory/boost/memory/pool_alloc.hpp (original)
+++ sandbox/memory/boost/memory/pool_alloc.hpp 2009-11-14 15:17:54 EST (Sat, 14 Nov 2009)
@@ -1,5 +1,5 @@
 //
-// boost/memory/fixed_alloc.hpp
+// boost/memory/pool_alloc.hpp
 //
 // Copyright (c) 2004 - 2008 xushiwei (xushiweizh_at_[hidden])
 //
@@ -9,21 +9,17 @@
 //
 // See http://www.boost.org/libs/memory/index.htm for documentation.
 //
-#ifndef BOOST_MEMORY_FIXED_ALLOC_HPP
-#define BOOST_MEMORY_FIXED_ALLOC_HPP
+#ifndef BOOST_MEMORY_POOL_ALLOC_HPP
+#define BOOST_MEMORY_POOL_ALLOC_HPP
 
 #ifndef BOOST_MEMORY_BASIC_HPP
 #include "basic.hpp"
 #endif
 
-#ifndef BOOST_MEMORY_CONTAINER_DCL_LIST_HPP
-#include "container/dcl_list.hpp"
-#endif
-
 NS_BOOST_MEMORY_BEGIN
 
 // -------------------------------------------------------------------------
-// class fixed_alloc
+// class pool_alloc
 
 #pragma pack(1)
 
@@ -45,13 +41,11 @@
 #endif
 
 template <class PolicyT>
-class fixed_alloc
+class pool_alloc
 {
 private:
- fixed_alloc(const fixed_alloc&);
- void operator=(const fixed_alloc&);
-
- void swap(fixed_alloc& o); // NO SWAP: dcl_list
+ pool_alloc(const pool_alloc&);
+ void operator=(const pool_alloc&);
 
 public:
         typedef typename PolicyT::alloc_type alloc_type;
@@ -62,69 +56,60 @@
 protected:
         struct MemBlock;
         friend struct MemBlock;
-
- struct Header : public dcl_list_node<MemBlock>
- {
- size_t nUsed;
- };
 
- enum { HeaderSize = sizeof(Header) };
+ enum { HeaderSize = sizeof(void*) };
         enum { BlockSize = MemBlockSize - HeaderSize };
 
- struct MemBlock : Header
+ struct MemBlock
         {
+ MemBlock* pPrev;
                 char buffer[BlockSize];
         };
 
- struct ChunkHeader
+ struct FreeChunk
         {
- MemBlock* pBlock;
+ FreeChunk* pPrev;
         };
 
- struct FreeChunk : public dcl_list_node<FreeChunk>
- {
- };
-
- enum { ChunkHeaderSize = sizeof(ChunkHeader) };
         enum { MinElemBytes = sizeof(FreeChunk) };
 
- dcl_list<FreeChunk> m_freelist;
- dcl_list<MemBlock> m_blks;
+ FreeChunk* m_freelist;
+ MemBlock* m_blks;
         size_type m_cbChunk;
         size_type m_nChunkPerBlock;
- MemBlock* m_lastBlock;
         alloc_type m_alloc;
 
 private:
         void BOOST_MEMORY_CALL init_(size_type cbElem)
         {
                 cbElem = ROUND(cbElem, sizeof(void*));
- m_cbChunk = MAX(cbElem, MinElemBytes) + ChunkHeaderSize;
- m_lastBlock = NULL;
+ m_cbChunk = MAX(cbElem, MinElemBytes);
                 m_nChunkPerBlock = BlockSize/m_cbChunk;
+ m_freelist = NULL;
+ m_blks = NULL;
 
                 BOOST_MEMORY_ASSERT(m_nChunkPerBlock > 0);
         }
         
 public:
- explicit fixed_alloc(size_type cbElem)
+ explicit pool_alloc(size_type cbElem)
         {
                 init_(cbElem);
         }
 
- fixed_alloc(alloc_type alloc, size_type cbElem) : m_alloc(alloc)
+ pool_alloc(alloc_type alloc, size_type cbElem) : m_alloc(alloc)
         {
                 init_(cbElem);
         }
 
- ~fixed_alloc()
+ ~pool_alloc()
         {
                 clear();
         }
 
         size_type BOOST_MEMORY_CALL alloc_size() const
         {
- return m_cbChunk - ChunkHeaderSize;
+ return m_cbChunk;
         }
 
         alloc_type BOOST_MEMORY_CALL get_alloc() const
@@ -135,96 +120,80 @@
         void BOOST_MEMORY_CALL clear()
         {
                 MemBlock* nextBlk;
- for (MemBlock* blk = this->m_blks.first(); !this->m_blks.done(blk); blk = nextBlk)
+ for (MemBlock* blk = m_blks; blk; blk = nextBlk)
                 {
- nextBlk = blk->next();
+ nextBlk = blk->pPrev;
                         m_alloc.deallocate(blk);
                 }
- this->m_blks.clear();
- this->m_freelist.clear();
+ m_blks = NULL;
+ m_freelist = NULL;
         }
 
 private:
- __forceinline MemBlock*& BOOST_MEMORY_CALL chunkHeader_(void* const p)
- {
- return ((ChunkHeader*)p - 1)->pBlock;
- }
-
- void BOOST_MEMORY_CALL do_allocate_block_()
+ void* BOOST_MEMORY_CALL do_allocate_()
         {
                 MemBlock* const blk = (MemBlock*)m_alloc.allocate(sizeof(MemBlock));
- m_blks.push_front(blk);
- m_lastBlock = blk;
+ blk->pPrev = m_blks;
+ m_blks = blk;
 
                 blk->nUsed = 0;
 
- char* p = blk->buffer + ChunkHeaderSize;
- for (size_type i = m_nChunkPerBlock; i--; p += m_cbChunk)
- {
- chunkHeader_(p) = blk;
- m_freelist.push_front((FreeChunk*)p);
- }
-
- BOOST_MEMORY_ASSERT(!m_freelist.empty());
- }
-
- void BOOST_MEMORY_CALL do_deallocate_block_(MemBlock* const blk)
- {
- char* p = blk->buffer + ChunkHeaderSize;
- for (size_type i = m_nChunkPerBlock; i--; p += m_cbChunk)
+ FreeChunk* p = (FreeChunk*)blk->buffer;
+ p->pPrev = m_freelist;
+ for (size_type i = m_nChunkPerBlock; --i;)
                 {
- ((FreeChunk*)p)->erase();
+ FreeChunk* const n = (FreeChunk*)((char*)p + m_cbChunk);
+ n->pPrev = p;
+ p = n;
                 }
+ m_freelist = p->pPrev;
 
- blk->erase();
-
- m_alloc.deallocate(blk);
+ BOOST_MEMORY_DBG_FILL(p, alloc_size());
+ return p;
         }
 
 public:
         __forceinline void* BOOST_MEMORY_CALL allocate()
         {
- if (m_freelist.empty())
- do_allocate_block_();
-
- void* p = &m_freelist.front();
- ++chunkHeader_(p)->nUsed;
- m_freelist.pop_front();
-
- BOOST_MEMORY_DBG_FILL(p, alloc_size());
- return p;
+ if (m_freelist)
+ {
+ FreeChunk* p = m_freelist;
+ m_freelist = p->pPrev;
+ BOOST_MEMORY_DBG_FILL(p, alloc_size());
+ return p;
+ }
+ return do_allocate_();
         }
 
         __forceinline void* BOOST_MEMORY_CALL allocate(size_t cb)
         {
                 BOOST_MEMORY_ASSERT(cb <= alloc_size());
+
                 return allocate();
         }
 
         __forceinline void BOOST_MEMORY_CALL deallocate(void* const p)
         {
- MemBlock* const blk = chunkHeader_(p);
-
- BOOST_MEMORY_ASSERT(blk->nUsed > 0 && blk->nUsed <= m_nChunkPerBlock);
                 BOOST_MEMORY_DBG_FILL(p, alloc_size());
 
- m_freelist.push_back((FreeChunk*)p); // NOTE: we don't use push_front! why?
- if (--blk->nUsed == 0 && blk != m_lastBlock)
- do_deallocate_block_(blk);
+ ((FreeChunk*)p)->pPrev = m_freelist;
+ m_freelist = (FreeChunk*)p;
         }
 
         __forceinline void BOOST_MEMORY_CALL deallocate(void* const p, size_t cb)
         {
                 BOOST_MEMORY_ASSERT(cb == alloc_size());
- deallocate(p);
+ BOOST_MEMORY_DBG_FILL(p, alloc_size());
+
+ ((FreeChunk*)p)->pPrev = m_freelist;
+ m_freelist = (FreeChunk*)p;
         }
 };
 
 #pragma pack()
 
 // -------------------------------------------------------------------------
-// $Log: $
 
 NS_BOOST_MEMORY_END
 
-#endif /* BOOST_MEMORY_FIXED_ALLOC_HPP */
+#endif /* BOOST_MEMORY_POOL_ALLOC_HPP */

Modified: sandbox/memory/boost/memory/pools.hpp
==============================================================================
--- sandbox/memory/boost/memory/pools.hpp (original)
+++ sandbox/memory/boost/memory/pools.hpp 2009-11-14 15:17:54 EST (Sat, 14 Nov 2009)
@@ -67,7 +67,7 @@
 
 public:
         typedef size_t size_type;
- typedef fixed_alloc<PolicyT> pool_type;
+ typedef pool_alloc<PolicyT> pool_type;
         typedef region_alloc<PolicyT, m_fPreAlloc> region_alloc_type;
         typedef typename pool_type::alloc_type block_pool_type;
 
@@ -79,13 +79,13 @@
         enum { MIN_BYTES1 = ALIGN1 };
         enum { MAX_BYTES1 = ALIGN1 * NPOOL1 };
 
- // 2^8-4, 2^9-4, 2^10-4, 2^11-4, 2^12-4, 2^13-4
- enum { NPOOL2 = 6 };
- enum { PADDING2 = 4 };
+ // 2^8-16, 2^9-16, 2^10-16, 2^11-16, 2^12-16, 2^13-16, 2^14-16, 2^15-16
+ enum { PADDING2 = 16 };
         enum { MIN_BITS2 = 8 };
- enum { MAX_BITS2 = 13 };
- enum { MIN_BYTES2 = (2 << MIN_BITS2) - PADDING2 };
- enum { MAX_BYTES2 = (2 << MAX_BITS2) - PADDING2 };
+ enum { MAX_BITS2 = 15 };
+ enum { NPOOL2 = MAX_BITS2 - MIN_BITS2 + 1 };
+ enum { MIN_BYTES2 = (1 << MIN_BITS2) - PADDING2 };
+ enum { MAX_BYTES2 = (1 << MAX_BITS2) - PADDING2 };
 
         enum { NPOOL = NPOOL1 + NPOOL2 };
 

Modified: sandbox/memory/boost/memory/region_alloc.hpp
==============================================================================
--- sandbox/memory/boost/memory/region_alloc.hpp (original)
+++ sandbox/memory/boost/memory/region_alloc.hpp 2009-11-14 15:17:54 EST (Sat, 14 Nov 2009)
@@ -240,7 +240,6 @@
 #pragma pack()
 
 // -------------------------------------------------------------------------
-// $Log: region_alloc.hpp,v $
 
 NS_BOOST_MEMORY_END
 

Modified: sandbox/memory/boost/memory/scoped_alloc.hpp
==============================================================================
--- sandbox/memory/boost/memory/scoped_alloc.hpp (original)
+++ sandbox/memory/boost/memory/scoped_alloc.hpp 2009-11-14 15:17:54 EST (Sat, 14 Nov 2009)
@@ -28,7 +28,6 @@
 typedef region_alloc<NS_BOOST_MEMORY_POLICY::scoped> scoped_alloc;
 
 // -------------------------------------------------------------------------
-// $Log: scoped_alloc.hpp,v $
 
 NS_BOOST_MEMORY_END
 

Modified: sandbox/memory/boost/memory/system_alloc.hpp
==============================================================================
--- sandbox/memory/boost/memory/system_alloc.hpp (original)
+++ sandbox/memory/boost/memory/system_alloc.hpp 2009-11-14 15:17:54 EST (Sat, 14 Nov 2009)
@@ -34,7 +34,7 @@
 class stdlib_alloc
 {
 public:
- enum { Padding = 32 /* must >= sizeof(AllocateHeader) */ };
+ enum { Padding = 16 /* must >= sizeof(AllocateHeader) */ };
 
         static void* BOOST_MEMORY_CALL allocate(size_t cb) {
                 return malloc(cb);
@@ -76,7 +76,7 @@
 class sys
 {
 public:
- enum { MemBlockBytes = 16384 /* 16k */ };
+ enum { MemBlockBytes = 65536 /* 64k */ };
 
 public:
         typedef system_alloc alloc_type;
@@ -92,7 +92,6 @@
 NS_BOOST_MEMORY_POLICY_END
 
 // =========================================================================
-// $Log: $
 
 NS_BOOST_MEMORY_END
 

Modified: sandbox/memory/boost/memory/type_traits.hpp
==============================================================================
--- sandbox/memory/boost/memory/type_traits.hpp (original)
+++ sandbox/memory/boost/memory/type_traits.hpp 2009-11-14 15:17:54 EST (Sat, 14 Nov 2009)
@@ -261,7 +261,6 @@
 BOOST_MEMORY_DECL_CTYPE_(unsigned long);
 
 // =========================================================================
-// $Log: $
 
 NS_BOOST_MEMORY_END
 


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