Boost logo

Boost-Commit :

From: xushiweizh_at_[hidden]
Date: 2008-04-29 13:13:41


Author: xushiwei
Date: 2008-04-29 13:13:40 EDT (Tue, 29 Apr 2008)
New Revision: 44885
URL: http://svn.boost.org/trac/boost/changeset/44885

Log:
gc_alloc
Added:
   sandbox/memory/boost/memory/gc_alloc.hpp (contents, props changed)
   sandbox/memory/boost/memory/policy.hpp (contents, props changed)
Text files modified:
   sandbox/memory/boost/memory.hpp | 4 +
   sandbox/memory/boost/memory/auto_alloc.hpp | 38 +++++++++++------
   sandbox/memory/boost/memory/basic.hpp | 36 ++++++++++++----
   sandbox/memory/boost/memory/scoped_alloc.hpp | 14 ++++-
   sandbox/memory/libs/memory/src/block_pool.cpp | 2
   sandbox/memory/libs/memory/test/memory/simple_examples.cpp | 84 ++++++++++++++++++++++++---------------
   sandbox/memory/libs/memory/test/test.cpp | 4 +
   7 files changed, 119 insertions(+), 63 deletions(-)

Modified: sandbox/memory/boost/memory.hpp
==============================================================================
--- sandbox/memory/boost/memory.hpp (original)
+++ sandbox/memory/boost/memory.hpp 2008-04-29 13:13:40 EDT (Tue, 29 Apr 2008)
@@ -22,6 +22,10 @@
 #include "memory/scoped_alloc.hpp"
 #endif
 
+#ifndef __BOOST_MEMORY_GC_ALLOC_HPP__
+#include "memory/gc_alloc.hpp"
+#endif
+
 // -------------------------------------------------------------------------
 // class stl_alloc
 

Modified: sandbox/memory/boost/memory/auto_alloc.hpp
==============================================================================
--- sandbox/memory/boost/memory/auto_alloc.hpp (original)
+++ sandbox/memory/boost/memory/auto_alloc.hpp 2008-04-29 13:13:40 EDT (Tue, 29 Apr 2008)
@@ -16,6 +16,10 @@
 #include "system_alloc.hpp"
 #endif
 
+#ifndef __BOOST_MEMORY_POLICY_HPP__
+#include "policy.hpp"
+#endif
+
 __NS_BOOST_BEGIN
 
 // -------------------------------------------------------------------------
@@ -29,14 +33,19 @@
 
 public:
         enum { MemBlockSize = _Policy::MemBlockSize };
- enum { HeaderSize = sizeof(void*) };
- enum { BlockSize = MemBlockSize - HeaderSize };
         enum { IsGCAllocator = TRUE };
 
         typedef _Alloc allocator_type;
 
+private:
+ enum { HeaderSize = sizeof(void*) };
+ enum { BlockSize = MemBlockSize - HeaderSize };
+
 #pragma pack(1)
 private:
+ struct _MemBlock;
+ friend struct _MemBlock;
+
         struct _MemBlock
         {
                 _MemBlock* pPrev;
@@ -62,19 +71,27 @@
                 return (_MemBlock*)(m_begin - HeaderSize);
         }
 
+ void BOOST_MEMORY_CALL _Init()
+ {
+ _MemBlock* pNew = (_MemBlock*)m_alloc.allocate(sizeof(_MemBlock));
+ pNew->pPrev = NULL;
+ m_begin = pNew->buffer;
+ m_end = (char*)pNew + m_alloc.alloc_size(pNew);
+ }
+
 public:
         region_alloc() : m_destroyChain(NULL)
         {
- m_begin = m_end = (char*)HeaderSize;
+ _Init();
         }
         explicit region_alloc(_Alloc alloc) : m_alloc(alloc), m_destroyChain(NULL)
         {
- m_begin = m_end = (char*)HeaderSize;
+ _Init();
         }
         explicit region_alloc(region_alloc& owner)
                 : m_alloc(owner.m_alloc), m_destroyChain(NULL)
         {
- m_begin = m_end = (char*)HeaderSize;
+ _Init();
         }
 
         ~region_alloc()
@@ -117,7 +134,7 @@
         template <class Type>
         Type* BOOST_MEMORY_CALL newArray(size_t count, Type* zero)
         {
- Type* array = (Type*)destructor_traits<Type>::allocArrayBuf(*this, count);
+ Type* array = (Type*)destructor_traits<Type>::allocArray(*this, count);
                 return constructor_traits<Type>::constructArray(array, count);
         }
 
@@ -192,14 +209,7 @@
 // -------------------------------------------------------------------------
 // class auto_alloc
 
-class _sys_alloc
-{
-public:
- enum { MemBlockSize = BOOST_MEMORY_BLOCK_SIZE };
- typedef system_alloc allocator_type;
-};
-
-typedef region_alloc<_sys_alloc> auto_alloc;
+typedef region_alloc<policy::sys> auto_alloc;
 
 // -------------------------------------------------------------------------
 // $Log: auto_alloc.hpp,v $

Modified: sandbox/memory/boost/memory/basic.hpp
==============================================================================
--- sandbox/memory/boost/memory/basic.hpp (original)
+++ sandbox/memory/boost/memory/basic.hpp 2008-04-29 13:13:40 EDT (Tue, 29 Apr 2008)
@@ -26,14 +26,10 @@
 #include <malloc.h> // _alloca
 #endif
 
-#ifndef _CrtSetDbgFlag
-
-#if defined(_MSC_VER)
+#if defined(_MSC_VER) && !defined(_INC_CRTDBG)
 #include <crtdbg.h> // _CrtSetDbgFlag
 #endif
 
-#endif
-
 // =========================================================================
 
 #ifndef BOOST_MEMORY_CALL
@@ -131,13 +127,24 @@
         }
 
         template <class AllocT>
- static void* BOOST_MEMORY_CALL allocArrayBuf(AllocT& alloc, size_t count)
+ static void* BOOST_MEMORY_CALL allocArray(AllocT& alloc, size_t count)
         {
- array_destructor_header* hdr = (array_destructor_header*)alloc.allocate(
- sizeof(array_destructor_header)+sizeof(Type)*count, destructArray);
+ array_destructor_header* hdr =
+ (array_destructor_header*)alloc.allocate(
+ sizeof(array_destructor_header)+sizeof(Type)*count, destructArray);
                 hdr->count = count;
                 return hdr + 1;
         }
+
+ static void* BOOST_MEMORY_CALL getArrayBuffer(void* array)
+ {
+ return (array_destructor_header*)array - 1;
+ }
+
+ static size_t BOOST_MEMORY_CALL getArraySize(void* array)
+ {
+ return ((array_destructor_header*)array - 1)->count;
+ }
 };
 
 template <class Type>
@@ -164,9 +171,18 @@
         static void BOOST_MEMORY_CALL destructArrayN(Type* array, size_t count) {} \
                                                                                                                                                         \
         template <class AllocT> \
- static void* BOOST_MEMORY_CALL allocArrayBuf(AllocT& alloc, size_t count) { \
+ static void* BOOST_MEMORY_CALL allocArray(AllocT& alloc, size_t count) {\
                 return alloc.allocate(sizeof(Type)*count); \
         } \
+ \
+ static void* BOOST_MEMORY_CALL getArrayBuffer(void* array) { \
+ return array; \
+ } \
+ \
+ static size_t BOOST_MEMORY_CALL getArraySize(void* array) { \
+ BOOST_MEMORY_ASSERT( !"Don't call me!!!" ); \
+ return 0; \
+ } \
 }; \
 __NS_BOOST_END
 
@@ -250,7 +266,7 @@
 
 inline void BOOST_MEMORY_CALL enableMemoryLeakCheck()
 {
-#ifdef _CrtSetDbgFlag
+#if defined(_MSC_VER)
         _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_LEAK_CHECK_DF);
 #endif
 }

Added: sandbox/memory/boost/memory/gc_alloc.hpp
==============================================================================
--- (empty file)
+++ sandbox/memory/boost/memory/gc_alloc.hpp 2008-04-29 13:13:40 EDT (Tue, 29 Apr 2008)
@@ -0,0 +1,383 @@
+//
+// boost/memory/gc_alloc.hpp
+//
+// Copyright (c) 2004 - 2008 xushiwei (xushiweizh_at_[hidden])
+//
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/memory/index.htm for documentation.
+//
+#ifndef __BOOST_MEMORY_GC_ALLOC_HPP__
+#define __BOOST_MEMORY_GC_ALLOC_HPP__
+
+#ifndef __BOOST_MEMORY_SCOPED_ALLOC_HPP__
+#include "scoped_alloc.hpp"
+#endif
+
+__NS_BOOST_BEGIN
+
+// -------------------------------------------------------------------------
+// class gen_alloc
+
+#ifndef MAX
+#define MAX(a, b) ((a) < (b) ? (b) : (a))
+#endif
+
+#ifndef MIN
+#define MIN(a, b) ((a) < (b) ? (a) : (b))
+#endif
+
+template <class _Policy>
+class gen_alloc
+{
+private:
+ typedef typename _Policy::allocator_type _Alloc;
+ typedef typename _Policy::huge_gc_allocator _HugeGCAlloc;
+ typedef size_t _HeaderSizeT;
+
+public:
+ enum { MemBlockSize = _Policy::MemBlockSize };
+ enum { IsGCAllocator = TRUE };
+
+ typedef _Alloc allocator_type;
+ typedef _HugeGCAlloc huge_gc_allocator;
+
+#pragma pack(1)
+private:
+ enum _MemNodeType {
+ nodeFree = 0,
+ nodeAlloced = 1,
+ nodeAllocedWithDestructor = 3,
+ };
+
+ struct _MemHeader
+ {
+ _HeaderSizeT cbSize : 30;
+ _HeaderSizeT blkType : 2;
+ };
+
+ struct _MemHeaderEx;
+ struct _DestroyInfo
+ {
+ _MemHeaderEx* pPrev;
+ destructor_t fnDestroy;
+ };
+
+ struct _MemHeaderEx // = _MemHeader + _DestroyInfo
+ {
+ _HeaderSizeT cbSize : 30;
+ _HeaderSizeT blkType : 2;
+
+ _MemHeaderEx* pPrev;
+ destructor_t fnDestroy;
+
+ void BOOST_MEMORY_CALL destruct() {
+ if (blkType == nodeAllocedWithDestructor) {
+ blkType = nodeFree;
+ fnDestroy(this + 1);
+ }
+ }
+ };
+
+ friend struct _MemHeaderEx;
+
+ struct _FreeMemHeader
+ {
+ _HeaderSizeT cbSize;
+ _HeaderSizeT BOOST_MEMORY_CALL getBlockType() const {
+ return ((_MemHeader*)this)->blkType;
+ }
+ char* BOOST_MEMORY_CALL getData() const {
+ return (char*)(this + 1);
+ }
+ };
+
+ struct _MemBlock
+ {
+ _MemBlock* pPrev;
+ char buffer[1];
+
+ class Enumerator
+ {
+ private:
+ char* m_start;
+ char* m_last;
+
+ public:
+ Enumerator(_Alloc& alloc, _MemBlock* block) {
+ m_start = block->buffer;
+ m_last = (char*)block + alloc.alloc_size(block);
+ }
+ _MemHeader* BOOST_MEMORY_CALL first() const {
+ return (_MemHeader*)m_start;
+ }
+ _MemHeader* BOOST_MEMORY_CALL next() {
+ m_start += sizeof(_MemHeader) + ((_MemHeader*)m_start)->cbSize;
+ return (_MemHeader*)m_start;
+ }
+ bool BOOST_MEMORY_CALL done() const {
+ return m_start >= m_last;
+ }
+ };
+ };
+
+ struct _FreeListNode
+ {
+ _HeaderSizeT cbSize;
+ _FreeListNode* pPrev;
+ };
+#pragma pack()
+
+ char* m_begin;
+ char* m_end;
+ _Alloc m_alloc;
+ _MemHeaderEx* m_destroyChain;
+ _MemBlock* m_blockList;
+ _FreeListNode* m_freeList;
+ _HugeGCAlloc m_hugeAlloc;
+
+private:
+ const gen_alloc& operator=(const gen_alloc&);
+
+ static bool BOOST_MEMORY_CALL _IsValid(void* obj, destructor_t fn)
+ {
+ _MemHeaderEx* node = (_MemHeaderEx*)obj - 1;
+ BOOST_MEMORY_ASSERT(node->fnDestroy == fn);
+ BOOST_MEMORY_ASSERT(node->cbSize == sizeof(Type) + sizeof(_DestroyInfo));
+ BOOST_MEMORY_ASSERT(node->blkType == nodeAllocedWithDestructor);
+ return node->fnDestroy == fn &&
+ node->cbSize == sizeof(Type) + sizeof(_DestroyInfo) &&
+ node->blkType == nodeAllocedWithDestructor;
+ }
+
+ static bool BOOST_MEMORY_CALL _IsValid(void* obj, int fnZero)
+ {
+ _MemHeader* node = (_MemHeader*)obj - 1;
+ BOOST_MEMORY_ASSERT(node->cbSize == sizeof(Type));
+ BOOST_MEMORY_ASSERT(node->blkType == nodeAlloced);
+ return node->cbSize == sizeof(Type) && node->blkType == nodeAlloced;
+ }
+
+ template <class Type>
+ static bool BOOST_MEMORY_CALL _IsValid(Type* obj)
+ {
+ return _IsValid(obj, destructor_traits<Type>::destruct);
+ }
+
+ template <class Type>
+ static bool BOOST_MEMORY_CALL _IsValidArray(Type* array, size_t count)
+ {
+ void* buf = destructor_traits<Type>::getArrayBuffer(array);
+ if (buf == array)
+ {
+ return _IsValid(buf, sizeof(Type)*count);
+ }
+ else
+ {
+ size_t count1 = destructor_traits<Type>::getArraySize(array);
+ BOOST_MEMORY_ASSERT(count1 == count);
+ bool fValid = _IsValid(buf, destructor_traits<Type>::destructArray);
+ return count1 == count && fValid;
+ }
+ }
+
+ void BOOST_MEMORY_CALL _Travel() const
+ {
+ _MemBlock* pHeader = m_blockList;
+ while (pHeader)
+ {
+ _MemBlock::Enumerator coll(pHeader->pPrev);
+ pHeader = pHeader->pPrev;
+ for (_MemHeader* it = coll.first(); !coll.done(); it = coll.next())
+ it;
+ }
+ }
+
+ _MemBlock* BOOST_MEMORY_CALL _NewMemBlock(size_t cbBlock)
+ {
+ _MemBlock* pNew = (_MemBlock*)m_alloc.allocate(cbBlock);
+ pNew->pPrev = m_blockList;
+ m_blockList = pNew;
+ return pNew;
+ }
+
+ void BOOST_MEMORY_CALL _Init()
+ {
+ _MemBlock* pNew = _NewMemBlock(MemBlockSize);
+ _MemHeader* p = (_MemHeader*)pNew->buffer;
+ p->blkType = nodeFree;
+ m_begin = (char*)(p + 1);
+ m_end = (char*)pNew + m_alloc.alloc_size(pNew);
+ }
+
+private:
+ enum { HeaderSize = sizeof(void*) };
+ enum { BlockSize = MemBlockSize - HeaderSize };
+ enum { AllocSizeBig = MIN(_Policy::AllocSizeBig, BlockSize/2) };
+ enum { AllocSizeHuge = (1 << 30) };
+ enum { RecycleSizeMin = MAX(_Policy::RecycleSizeMin, 128) };
+
+public:
+ gen_alloc() : m_blockList(NULL), m_freeList(NULL), m_destroyChain(NULL)
+ {
+ _Init();
+ }
+ explicit gen_alloc(_Alloc alloc)
+ : m_alloc(alloc), m_blockList(NULL), m_freeList(NULL), m_destroyChain(NULL)
+ {
+ _Init();
+ }
+ explicit gen_alloc(gen_alloc& owner)
+ : m_alloc(owner.m_alloc), m_blockList(NULL), m_freeList(NULL), m_destroyChain(NULL)
+ {
+ _Init();
+ }
+
+ ~gen_alloc()
+ {
+ clear();
+ }
+
+ void BOOST_MEMORY_CALL swap(gen_alloc& o)
+ {
+ std::swap(m_begin, o.m_begin);
+ std::swap(m_end, o.m_end);
+ std::swap(m_blockList, o.m_blockList);
+ std::swap(m_freeList, o.m_freeList);
+ std::swap(m_destroyChain, o.m_destroyChain);
+ m_alloc.swap(o.m_alloc);
+ m_hugeAlloc.swap(o.m_hugeAlloc);
+ }
+
+ void BOOST_MEMORY_CALL clear()
+ {
+ m_hugeAlloc.clear();
+ while (m_destroyChain)
+ {
+ _MemHeaderEx* curr = m_destroyChain;
+ m_destroyChain = m_destroyChain->pPrev;
+ curr->destruct();
+ }
+ _MemBlock* pHeader = m_blockList;
+ while (pHeader)
+ {
+ _MemBlock* pTemp = pHeader->pPrev;
+ m_alloc.deallocate(pHeader);
+ pHeader = pTemp;
+ }
+ m_begin = m_end = NULL;
+ m_blockList = NULL;
+ m_freeList = NULL;
+ }
+
+ template <class Type>
+ void BOOST_MEMORY_CALL destroy(Type* obj)
+ {
+ BOOST_MEMORY_ASSERT( _IsValid(obj) );
+
+ _MemHeader* p = (_MemHeader*)obj - 1;
+ p->blkType = nodeFree;
+ obj->~Type();
+ }
+
+ template <class Type>
+ Type* BOOST_MEMORY_CALL newArray(size_t count, Type* zero)
+ {
+ Type* array = (Type*)destructor_traits<Type>::allocArray(*this, count);
+ return constructor_traits<Type>::constructArray(array, count);
+ }
+
+ template <class Type>
+ void BOOST_MEMORY_CALL destroyArray(Type* array, size_t count)
+ {
+ BOOST_MEMORY_ASSERT( _IsValidArray(obj, count) );
+
+ void* buf = destructor_traits<Type>::getArrayBuffer(array);
+ _MemHeader* p = (_MemHeader*)buf - 1;
+ p->blkType = nodeFree;
+ destructor_traits<Type>::destructArrayN(array, count);
+ }
+
+ void* BOOST_MEMORY_CALL allocate(size_t cbData)
+ {
+ const size_t cb = cbData + sizeof(_MemHeader);
+ if ((size_t)(m_end - m_begin) < cb)
+ {
+ _MemBlock* pNew;
+ if (cb >= AllocSizeBig)
+ {
+ if (cbData >= AllocSizeHuge)
+ return m_hugeAlloc.allocate(cbData);
+
+ if (cb >= BlockSize)
+ {
+ pNew = _NewMemBlock(cb + HeaderSize);
+ m_blockList->pPrev = pNew;
+ m_blockList = pNew;
+ _MemHeader* p = (_MemHeader*)pNew->buffer;
+ p->blkType = nodeAlloced;
+ p->cbSize = cbData;
+ return p + 1;
+ }
+ pNew = _NewMemBlock(MemBlockSize);
+ }
+ else
+ {
+ pNew = _NewMemBlock(MemBlockSize);
+ }
+ _FreeMemHeader* old = (_FreeMemHeader*)m_begin - 1;
+ BOOST_MEMORY_ASSERT(old->getBlockType() == nodeFree);
+ old->cbSize = m_end - m_begin;
+ _MemHeader* p = (_MemHeader*)pNew->buffer;
+ p->blkType = nodeFree;
+ m_begin = (char*)(p + 1);
+ m_end = (char*)pNew + m_alloc.alloc_size(pNew);
+ }
+ _MemHeader* pAlloc = (_MemHeader*)(m_end -= cb);
+ pAlloc->blkType = nodeAlloced;
+ pAlloc->cbSize = cbData;
+ return pAlloc + 1;
+ }
+
+ void* BOOST_MEMORY_CALL allocate(size_t cb, destructor_t fn)
+ {
+ _DestroyInfo* pNode = (_DestroyInfo*)allocate(sizeof(_DestroyInfo) + cb);
+ pNode->fnDestroy = fn;
+ pNode->pPrev = m_destroyChain;
+ m_destroyChain = (_MemHeaderEx*)((char*)pNode - sizeof(_MemHeader));
+ return pNode + 1;
+ }
+
+ void* BOOST_MEMORY_CALL allocate(size_t cb, int fnZero)
+ {
+ return allocate(cb);
+ }
+
+ void BOOST_MEMORY_CALL deallocate(void* pData, size_t cbData)
+ {
+ if (cbData >= AllocSizeHuge)
+ return m_hugeAlloc.deallocate(p, cbData);
+
+ _MemHeader* p = (_MemHeader*)pData - 1;
+ BOOST_MEMORY_ASSERT(p->cbSize == cbData);
+ BOOST_MEMORY_ASSERT(p->blkType == nodeAlloced);
+
+ p->blkType = nodeFree;
+ }
+
+ __BOOST_FAKE_DBG_ALLOCATE();
+};
+
+// -------------------------------------------------------------------------
+// class gc_alloc
+
+typedef gen_alloc<policy::pool> gc_alloc;
+
+// -------------------------------------------------------------------------
+// $Log: gc_alloc.hpp,v $
+
+__NS_BOOST_END
+
+#endif /* __BOOST_MEMORY_GC_ALLOC_HPP__ */

Added: sandbox/memory/boost/memory/policy.hpp
==============================================================================
--- (empty file)
+++ sandbox/memory/boost/memory/policy.hpp 2008-04-29 13:13:40 EDT (Tue, 29 Apr 2008)
@@ -0,0 +1,130 @@
+//
+// boost/memory/policy.hpp
+//
+// Copyright (c) 2004 - 2008 xushiwei (xushiweizh_at_[hidden])
+//
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// See http://www.boost.org/libs/memory/index.htm for documentation.
+//
+#ifndef __BOOST_MEMORY_POLICY_HPP__
+#define __BOOST_MEMORY_POLICY_HPP__
+
+#ifndef __BOOST_MEMORY_SYSTEM_ALLOC_HPP__
+#include "system_alloc.hpp"
+#endif
+
+__NS_BOOST_BEGIN
+
+// -------------------------------------------------------------------------
+// class simple_gc_alloc
+
+template <class _SysAlloc>
+class simple_gc_alloc
+{
+#pragma pack(1)
+private:
+ struct _DestroyNode
+ {
+ _DestroyNode* pPrev;
+ destructor_t fnDestroy;
+ };
+ struct _MemBlock
+ {
+ _MemBlock* pPrev;
+ };
+#pragma pack()
+
+ _MemBlock* m_memChain;
+ _DestroyNode* m_destroyChain;
+
+public:
+ simple_gc_alloc()
+ : m_memChain(NULL), m_destroyChain(NULL)
+ {
+ }
+
+ void BOOST_MEMORY_CALL swap(simple_gc_alloc& o)
+ {
+ std::swap(m_memChain, o.m_memChain);
+ std::swap(m_destroyChain, o.m_destroyChain);
+ }
+
+ void BOOST_MEMORY_CALL clear()
+ {
+ while (m_destroyChain)
+ {
+ _DestroyNode* curr = m_destroyChain;
+ m_destroyChain = m_destroyChain->pPrev;
+ curr->fnDestroy(curr + 1);
+ }
+ while (m_memChain)
+ {
+ _MemBlock* curr = m_memChain;
+ m_memChain = m_memChain->pPrev;
+ _SysAlloc::deallocate(m_memChain);
+ }
+ }
+
+ template <class Type>
+ void BOOST_MEMORY_CALL destroy(Type* obj)
+ {
+ // no action
+ }
+
+ void* BOOST_MEMORY_CALL allocate(size_t cb)
+ {
+ _MemBlock* p = (_MemBlock*)_SysAlloc::allocate(cb + sizeof(_MemBlock));
+ p->pPrev = m_memChain;
+ m_memChain = p;
+ return p + 1;
+ }
+
+ void* BOOST_MEMORY_CALL allocate(size_t cb, destructor_t fn)
+ {
+ _DestroyNode* pNode = (_DestroyNode*)allocate(cb + sizeof(_DestroyNode));
+ pNode->fnDestroy = fn;
+ pNode->pPrev = m_destroyChain;
+ m_destroyChain = pNode;
+ return pNode + 1;
+ }
+
+ void* BOOST_MEMORY_CALL allocate(size_t cb, int fnZero)
+ {
+ return allocate(cb);
+ }
+
+ void BOOST_MEMORY_CALL deallocate(void* p, size_t cb)
+ {
+ // no action
+ }
+};
+
+// -------------------------------------------------------------------------
+
+namespace policy {
+
+class sys
+{
+private:
+ enum { Default = 0 };
+
+public:
+ enum { MemBlockSize = BOOST_MEMORY_BLOCK_SIZE };
+ enum { AllocSizeBig = Default };
+ enum { RecycleSizeMin = 256 };
+
+ typedef system_alloc allocator_type;
+ typedef simple_gc_alloc<system_alloc> huge_gc_allocator;
+};
+
+}
+
+// -------------------------------------------------------------------------
+// $Log: policy.hpp,v $
+
+__NS_BOOST_END
+
+#endif /* __BOOST_MEMORY_POLICY_HPP__ */

Modified: sandbox/memory/boost/memory/scoped_alloc.hpp
==============================================================================
--- sandbox/memory/boost/memory/scoped_alloc.hpp (original)
+++ sandbox/memory/boost/memory/scoped_alloc.hpp 2008-04-29 13:13:40 EDT (Tue, 29 Apr 2008)
@@ -60,9 +60,12 @@
         typedef typename _Policy::allocator_type _Alloc;
         enum { m_cbBlock = _Policy::MemBlockSize };
 
+#pragma pack(1)
         struct _Block {
                 _Block* next;
         };
+#pragma pack()
+
         _Block* m_freeList;
 
         int m_nFree;
@@ -134,7 +137,7 @@
         }
 };
 
-typedef block_pool_imp<_sys_alloc> block_pool;
+typedef block_pool_imp<policy::sys> block_pool;
 
 // -------------------------------------------------------------------------
 // class tls_block_pool
@@ -173,14 +176,17 @@
 
 typedef proxy_alloc<block_pool, tls_block_pool> proxy_block_pool;
 
-class _pool_alloc
+namespace policy {
+
+class pool : public sys
 {
 public:
- enum { MemBlockSize = BOOST_MEMORY_BLOCK_SIZE };
         typedef proxy_block_pool allocator_type;
 };
 
-typedef region_alloc<_pool_alloc> scoped_alloc;
+}
+
+typedef region_alloc<policy::pool> scoped_alloc;
 
 // -------------------------------------------------------------------------
 // $Log: $

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-04-29 13:13:40 EDT (Tue, 29 Apr 2008)
@@ -33,7 +33,7 @@
         ~tls_block_pool_init() { _tls_blockPool.term(); }
 };
 
-tls_block_pool_init _tls_blockPoolInit;
+// tls_block_pool_init _tls_blockPoolInit;
 
 // -------------------------------------------------------------------------
 // $Log: $

Modified: sandbox/memory/libs/memory/test/memory/simple_examples.cpp
==============================================================================
--- sandbox/memory/libs/memory/test/memory/simple_examples.cpp (original)
+++ sandbox/memory/libs/memory/test/memory/simple_examples.cpp 2008-04-29 13:13:40 EDT (Tue, 29 Apr 2008)
@@ -16,50 +16,68 @@
 
 void testAutoAlloc()
 {
- boost::auto_alloc alloc;
- int* intObj = BOOST_NEW(alloc, int);
- int* intObjWithArg = BOOST_NEW(alloc, int)(10);
- int* intArray = BOOST_NEW_ARRAY(alloc, int, 100);
- int* intBuf = BOOST_ALLOC(alloc, int);
- int* intArrayBuf = BOOST_ALLOC_ARRAY(alloc, int, 100);
-
- boost::auto_alloc* subAlloc = BOOST_NEW(alloc, boost::auto_alloc);
- int* e = BOOST_NEW(*subAlloc, int);
+ boost::auto_alloc alloc;
+ int* intObj = BOOST_NEW(alloc, int);
+ int* intObjWithArg = BOOST_NEW(alloc, int)(10);
+ int* intArray = BOOST_NEW_ARRAY(alloc, int, 100);
+ int* intBuf = BOOST_ALLOC(alloc, int);
+ int* intArrayBuf = BOOST_ALLOC_ARRAY(alloc, int, 100);
+
+ boost::auto_alloc* subAlloc = BOOST_NEW(alloc, boost::auto_alloc);
+ int* e = BOOST_NEW(*subAlloc, int);
 }
 
 void testScopedAlloc()
 {
- boost::block_pool recycle;
- boost::scoped_alloc alloc(recycle);
-
- int* intObj = BOOST_NEW(alloc, int);
- int* intObjWithArg = BOOST_NEW(alloc, int)(10);
- int* intArray = BOOST_NEW_ARRAY(alloc, int, 100);
- int* intBuf = BOOST_ALLOC(alloc, int);
- int* intArrayBuf = BOOST_ALLOC_ARRAY(alloc, int, 100);
-
- boost::scoped_alloc* suballoc = BOOST_NEW(alloc, boost::scoped_alloc)(alloc);
- int* e = BOOST_NEW(*suballoc, int);
+ boost::block_pool recycle;
+ boost::scoped_alloc alloc(recycle);
+
+ int* intObj = BOOST_NEW(alloc, int);
+ int* intObjWithArg = BOOST_NEW(alloc, int)(10);
+ int* intArray = BOOST_NEW_ARRAY(alloc, int, 100);
+ int* intBuf = BOOST_ALLOC(alloc, int);
+ int* intArrayBuf = BOOST_ALLOC_ARRAY(alloc, int, 100);
+
+ boost::scoped_alloc* suballoc = BOOST_NEW(alloc, boost::scoped_alloc)(alloc);
+ int* e = BOOST_NEW(*suballoc, int);
 }
 
 void testTlsScopedAlloc()
 {
- boost::scoped_alloc alloc;
- // same as: boost::scoped_alloc(boost::tls_block_pool::instance());
-
- int* intObj = BOOST_NEW(alloc, int);
- int* intObjWithArg = BOOST_NEW(alloc, int)(10);
- int* intArray = BOOST_NEW_ARRAY(alloc, int, 100);
- int* intBuf = BOOST_ALLOC(alloc, int);
- int* intArrayBuf = BOOST_ALLOC_ARRAY(alloc, int, 100);
+ boost::scoped_alloc alloc;
+ // same as: boost::scoped_alloc(boost::tls_block_pool::instance());
+
+ int* intObj = BOOST_NEW(alloc, int);
+ int* intObjWithArg = BOOST_NEW(alloc, int)(10);
+ int* intArray = BOOST_NEW_ARRAY(alloc, int, 100);
+ int* intBuf = BOOST_ALLOC(alloc, int);
+ int* intArrayBuf = BOOST_ALLOC_ARRAY(alloc, int, 100);
+
+ boost::scoped_alloc* suballoc = BOOST_NEW(alloc, boost::scoped_alloc);
+ int* e = BOOST_NEW(*suballoc, int);
+}
 
- boost::scoped_alloc* suballoc = BOOST_NEW(alloc, boost::scoped_alloc);
- int* e = BOOST_NEW(*suballoc, int);
+void testGCAlloc()
+{
+ boost::gc_alloc alloc;
+ // same as: boost::scoped_alloc(boost::tls_block_pool::instance());
+
+ int* intObj = BOOST_NEW(alloc, int);
+ int* intObjWithArg = BOOST_NEW(alloc, int)(10);
+ int* intArray = BOOST_NEW_ARRAY(alloc, int, 100);
+ int* intBuf = BOOST_ALLOC(alloc, int);
+ int* intArrayBuf = BOOST_ALLOC_ARRAY(alloc, int, 100);
+
+ boost::gc_alloc* suballoc = BOOST_NEW(alloc, boost::gc_alloc);
+ int* e = BOOST_NEW(*suballoc, int);
 }
 
 void simpleExamples()
 {
- testAutoAlloc();
- testScopedAlloc();
- testTlsScopedAlloc();
+ boost::enableMemoryLeakCheck();
+// _CrtSetBreakAlloc(55);
+// testAutoAlloc();
+// testScopedAlloc();
+// testTlsScopedAlloc();
+ testGCAlloc();
 }

Modified: sandbox/memory/libs/memory/test/test.cpp
==============================================================================
--- sandbox/memory/libs/memory/test/test.cpp (original)
+++ sandbox/memory/libs/memory/test/test.cpp 2008-04-29 13:13:40 EDT (Tue, 29 Apr 2008)
@@ -10,6 +10,7 @@
 // See http://www.boost.org/libs/memory/index.htm for documentation.
 //
 
+#include <boost/memory.hpp>
 #include <boost/memory/linklib.hpp>
 
 void testStlContainers();
@@ -17,7 +18,8 @@
 
 int main()
 {
+ boost::tls_block_pool bp;
         simpleExamples();
- testStlContainers();
+// testStlContainers();
         return 0;
 }


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