From 45c04b44632c81d819feb8e4d648a8e500ad07b4 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sat, 29 Aug 2009 02:16:28 +0200 Subject: [PATCH] re-visit the command impl allocation; add a quick-n-dirty implementation based on heap allocation --- src/lib/allocationcluster.cpp | 8 ++--- src/lib/allocationcluster.hpp | 30 ++++++++--------- src/proc/control/command-registry.hpp | 6 ++-- src/proc/control/typed-allocation-manager.hpp | 32 ++++++++++++------- 4 files changed, 43 insertions(+), 33 deletions(-) diff --git a/src/lib/allocationcluster.cpp b/src/lib/allocationcluster.cpp index 8dcd5da6e..ae283e62f 100644 --- a/src/lib/allocationcluster.cpp +++ b/src/lib/allocationcluster.cpp @@ -83,7 +83,7 @@ namespace lib { void AllocationCluster::MemoryManager::reset (TypeInfo info) { - Lock instance(); + Lock sync(this); if (0 < mem_.size()) purge(); type_ = info; @@ -98,7 +98,7 @@ namespace lib { void AllocationCluster::MemoryManager::purge() { - Lock instance(); + Lock sync(this); REQUIRE (type_.killIt, "we need a deleter function"); REQUIRE (0 < type_.allocSize, "allocation size unknown"); @@ -122,7 +122,7 @@ namespace lib { inline void* AllocationCluster::MemoryManager::allocate() { - Lock instance(); + Lock sync(this); REQUIRE (0 < type_.allocSize); REQUIRE (top_ <= mem_.size()); @@ -142,7 +142,7 @@ namespace lib { inline void AllocationCluster::MemoryManager::commit (void* pendingAlloc) { - Lock instance(); + Lock sync(this); REQUIRE (pendingAlloc); ASSERT (top_ < mem_.size()); diff --git a/src/lib/allocationcluster.hpp b/src/lib/allocationcluster.hpp index be99f7329..304405d58 100644 --- a/src/lib/allocationcluster.hpp +++ b/src/lib/allocationcluster.hpp @@ -197,21 +197,21 @@ namespace lib { //-----implementation-details------------------------ struct AllocationCluster::TypeInfo - { - size_t allocSize; - void (*killIt)(void*); ///< deleter function - - template - TypeInfo(TY*) - : allocSize(sizeof(TY)), - killIt(&TypeSlot::kill) - { } - - TypeInfo() ///< denotes "unknown" type - : allocSize(0), - killIt(0) - { } - }; + { + size_t allocSize; + void (*killIt)(void*); ///< deleter function + + template + TypeInfo(TY*) + : allocSize(sizeof(TY)), + killIt(&TypeSlot::kill) + { } + + TypeInfo() ///< denotes "unknown" type + : allocSize(0), + killIt(0) + { } + }; diff --git a/src/proc/control/command-registry.hpp b/src/proc/control/command-registry.hpp index 9dd5206a9..1075b2f2d 100644 --- a/src/proc/control/command-registry.hpp +++ b/src/proc/control/command-registry.hpp @@ -142,9 +142,9 @@ namespace control { /** set up a new command implementation frame - * @return pointer to a newly created CommandImpl, allocated - * through the registry. The caller is responsible for - * deallocating this frame by calling #killCommandImpl + * @return shared-ptr owning a newly created CommandImpl, allocated + * through the registry and wired internally to invoke + * TypedAllocationManager#destroyElement for cleanup. */ template< typename SIG_OPER ///< signature of the command operation , typename SIG_CAPT ///< signature for capturing undo state diff --git a/src/proc/control/typed-allocation-manager.hpp b/src/proc/control/typed-allocation-manager.hpp index 397bc0e9f..4c91048d6 100644 --- a/src/proc/control/typed-allocation-manager.hpp +++ b/src/proc/control/typed-allocation-manager.hpp @@ -54,6 +54,9 @@ ** there is a facility allowing to create ref-counting handles and smart-pointers, ** which are internally tied to this memory manager through a deleter function. ** + ** @todo using a quick-n-dirty heap allocation implementation for now (8/09), + ** but should write a custom allocator based on cehteh's mpool! + ** ** @see CommandRegistry ** @see AllocationCluster (another custom allocation scheme, which could be united) ** @@ -66,30 +69,35 @@ //#include "pre.hpp" #include "lib/error.hpp" -//#include "lib/singleton.hpp" -//#include "lib/sync.hpp" #include "lib/format.hpp" #include "include/logging.h" -//#include "lib/bool-checkable.hpp" #include -//#include -//#include namespace control { using std::tr1::shared_ptr; -// using std::ostream; -// using std::string; /** - * TODO type comment + * Foundation for a custom allocation manager, + * tracking the created objects by smart-ptrs. + * The public interface provides forwarding functions + * to invoke the ctor of the objects to be created, thereby + * placing them into the storage maintained by a low-level + * allocator or pooled storage manager. The created smart-ptr + * owns the new object and is wired internally to #releaseSlot. + * Subclasses may also directly allocate and de-allocate + * such a (typed) storage slot. + * + * @todo currently (as of 8/09) the low-level pooled allocator + * isn't implemented; instead we do just heap allocations. + * see Ticket 231 */ class TypedAllocationManager { @@ -259,8 +267,8 @@ namespace control { Slot allocateSlot () { - UNIMPLEMENTED ("redirect to the corresponding pool allocator"); - void* space = 0; + TODO ("redirect to the corresponding pool allocator"); + void* space = new char[sizeof(XX)]; return Slot (this, space); } @@ -268,7 +276,9 @@ namespace control { void releaseSlot (void* entry) { - UNIMPLEMENTED ("redirect to the corresponding pool allocator"); + TODO ("redirect to the corresponding pool allocator"); + typedef char Storage[sizeof(XX)]; + delete[] reinterpret_cast (entry); }