|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r52606 - sandbox/memory/boost/memory
From: xushiweizh_at_[hidden]
Date: 2009-04-26 13:34:44
Author: xushiwei
Date: 2009-04-26 13:34:43 EDT (Sun, 26 Apr 2009)
New Revision: 52606
URL: http://svn.boost.org/trac/boost/changeset/52606
Log:
typed_alloc -> object_pool
Added:
sandbox/memory/boost/memory/typed_alloc.hpp (contents, props changed)
Text files modified:
sandbox/memory/boost/memory/auto_alloc.hpp | 5 +++--
sandbox/memory/boost/memory/basic.hpp | 8 ++++++++
sandbox/memory/boost/memory/fixed_alloc.hpp | 2 +-
3 files changed, 12 insertions(+), 3 deletions(-)
Modified: sandbox/memory/boost/memory/auto_alloc.hpp
==============================================================================
--- sandbox/memory/boost/memory/auto_alloc.hpp (original)
+++ sandbox/memory/boost/memory/auto_alloc.hpp 2009-04-26 13:34:43 EDT (Sun, 26 Apr 2009)
@@ -31,10 +31,11 @@
{
private:
typedef region_alloc<NS_BOOST_MEMORY_POLICY::stdlib> BaseClass;
-
+ typedef BaseClass::alloc_type AllocT;
+
public:
auto_alloc() {}
- explicit auto_alloc(auto_alloc&) {}
+ explicit auto_alloc(AllocT alloc) {}
__forceinline void BOOST_MEMORY_CALL swap(auto_alloc& o) {
BaseClass::swap(o);
Modified: sandbox/memory/boost/memory/basic.hpp
==============================================================================
--- sandbox/memory/boost/memory/basic.hpp (original)
+++ sandbox/memory/boost/memory/basic.hpp 2009-04-26 13:34:43 EDT (Sun, 26 Apr 2009)
@@ -56,6 +56,14 @@
#define BOOST_MEMORY_ASSERT(e) BOOST_DETAIL_ASSERT(e)
#endif
+#ifndef BOOST_MEMORY_STATIC_ASSERT
+#if defined(BOOST_STATIC_ASSERT)
+#define BOOST_MEMORY_STATIC_ASSERT(e) BOOST_STATIC_ASSERT(e)
+#else
+#define BOOST_MEMORY_STATIC_ASSERT(e) BOOST_DETAIL_ASSERT(e)
+#endif
+#endif
+
// -------------------------------------------------------------------------
#if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
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-26 13:34:43 EDT (Sun, 26 Apr 2009)
@@ -50,7 +50,7 @@
typedef size_t size_type;
#pragma pack(1)
-private:
+protected:
struct MemBlock;
friend struct MemBlock;
Added: sandbox/memory/boost/memory/typed_alloc.hpp
==============================================================================
--- (empty file)
+++ sandbox/memory/boost/memory/typed_alloc.hpp 2009-04-26 13:34:43 EDT (Sun, 26 Apr 2009)
@@ -0,0 +1,177 @@
+//
+// boost/memory/typed_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_TYPED_ALLOC_HPP
+#define BOOST_MEMORY_TYPED_ALLOC_HPP
+
+NS_BOOST_MEMORY_BEGIN
+
+// -------------------------------------------------------------------------
+// class norm_typed_alloc
+
+template <class Type, class PolicyT>
+class norm_typed_alloc : private fixed_alloc<PolicyT>
+{
+private:
+ typedef fixed_alloc<PolicyT> PoolT;
+
+#pragma pack(1)
+protected:
+ struct ChunkHeader
+ {
+ union
+ {
+ MemBlock* pBlock;
+ size_t tag;
+ };
+ };
+#pragma pack()
+
+protected:
+ size_t BOOST_MEMORY_CALL is_allocated_(void*p )
+ {
+ return 1 & ((ChunkHeader*)p - 1)->tag;
+ }
+
+ void BOOST_MEMORY_CALL mark_allocated_(void* p)
+ {
+ BOOST_MEMORY_ASSERT(!is_allocated_(p));
+ ++((ChunkHeader*)p - 1)->tag;
+ }
+
+ void BOOST_MEMORY_CALL mark_deallocated_(void* p)
+ {
+ BOOST_MEMORY_ASSERT(is_allocated_(p));
+ --((ChunkHeader*)p - 1)->tag;
+ }
+
+public:
+ typedef PoolT pool_type;
+
+public:
+ using PoolT::get_alloc;
+
+public:
+ norm_typed_alloc() : PoolT(sizeof(Type))
+ {
+ BOOST_MEMORY_STATIC_ASSERT(sizeof(ChunkHeader) == sizeof(typename PoolT::ChunkHeader));
+ }
+
+ explicit norm_typed_alloc(AllocT alloc) : PoolT(alloc, sizeof(Type))
+ {
+ BOOST_MEMORY_STATIC_ASSERT(sizeof(ChunkHeader) == sizeof(typename PoolT::ChunkHeader));
+ }
+
+ ~norm_typed_alloc()
+ {
+ clear();
+ }
+
+ pool_type& BOOST_MEMORY_CALL get_pool()
+ {
+ return *this;
+ }
+
+public:
+ __forceinline void BOOST_MEMORY_CALL clear()
+ {
+ // ...
+ }
+
+#if defined(BOOST_MEMORY_NO_STRICT_EXCEPTION_SEMANTICS)
+ __forceinline void* BOOST_MEMORY_CALL allocate(size_t cb, destructor_t fn)
+ {
+ BOOST_MEMORY_ASSERT(fn == BOOST_MEMORY_DESTRUCTOR(Type));
+ void* p = PoolT::allocate(cb);
+ manage(p, fn);
+ return p;
+ }
+#endif
+
+ __forceinline void* BOOST_MEMORY_CALL unmanaged_alloc(size_t cb, destructor_t fn) {
+ BOOST_MEMORY_ASSERT(fn == BOOST_MEMORY_DESTRUCTOR(Type));
+ return PoolT::allocate(cb);
+ }
+
+ __forceinline void BOOST_MEMORY_CALL manage(void* p, destructor_t fn) {
+ BOOST_MEMORY_ASSERT(fn == BOOST_MEMORY_DESTRUCTOR(Type));
+ mark_allocated_(p);
+ }
+
+ void BOOST_MEMORY_CALL destroy(Type* obj) {
+ mark_deallocated_(obj);
+ obj->~Type();
+ return PoolT::deallocate(obj);
+ }
+};
+
+// -------------------------------------------------------------------------
+// class typed_alloc
+
+#if defined(_MSC_VER) && (_MSC_VER <= 1200) // VC++ 6.0
+
+template <class Type, class PolicyT, int hasDestructor>
+struct typed_alloc_base_traits_
+{
+ template <int hasDestructor>
+ struct traits_ {
+ typedef norm_typed_alloc<Type, PolicyT> type;
+ };
+
+ template <>
+ struct traits_<0> {
+ typedef pod_typed_alloc<Type, PolicyT> type;
+ };
+
+ typedef typename traits_<hasDestructor>::type type;
+};
+
+#else
+
+template <class Type, class PolicyT, int hasDestructor>
+struct typed_alloc_base_traits_ {
+ typedef norm_typed_alloc<Type, PolicyT> type;
+};
+
+template <class Type, class PolicyT>
+struct typed_alloc_base_traits_<Type, PolicyT, 0> {
+ typedef pod_typed_alloc<Type, PolicyT> type;
+};
+
+#endif
+
+//
+// class typed_alloc
+//
+
+template <class Type, class PolicyT>
+class typed_alloc :
+ public typed_alloc_base_traits_<Type, PolicyT, destructor_traits<Type>::hasDestructor>::type
+{
+private:
+ typedef typed_alloc_base_traits_<Type, PolicyT, destructor_traits<Type>::hasDestructor>::type Base;
+ typedef typename Base::alloc_type AllocT;
+
+public:
+ typed_alloc() :
+ Base(sizeof(Type)) {
+ }
+ explicit typed_alloc(AllocT alloc) :
+ Base(alloc, sizeof(Type)) {
+ }
+};
+
+// -------------------------------------------------------------------------
+// $Log: $
+
+NS_BOOST_MEMORY_END
+
+#endif /* BOOST_MEMORY_TYPED_ALLOC_HPP */
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