From a00edd2a84c71e23b3098de7486ffb9a0d385f81 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Tue, 28 Oct 2008 06:07:23 +0100 Subject: [PATCH] cluster datastructure works, finally. WIP still a bug somewhere in the pseudo-memory manager (de-allocation fails) --- src/lib/allocationcluster.cpp | 3 +-- src/lib/allocationcluster.hpp | 31 +++++++++---------------------- 2 files changed, 10 insertions(+), 24 deletions(-) diff --git a/src/lib/allocationcluster.cpp b/src/lib/allocationcluster.cpp index 118abbe23..868496a22 100644 --- a/src/lib/allocationcluster.cpp +++ b/src/lib/allocationcluster.cpp @@ -148,7 +148,6 @@ namespace lib { * is managed by a separate instance of the low-level memory manager. */ AllocationCluster::AllocationCluster() -// : configParam_ (new Configmap), { TRACE (buildermem, "new AllocationCluster"); } @@ -203,7 +202,7 @@ namespace lib { Thread::Lock guard SIDEEFFECT; /////TODO: decide tradeoff: lock just the instance, or lock the AllocationCluster class? if (slot > typeHandlers_.size()) - typeHandlers_.resize(slot); /////////////////////////////TODO: still a fundamental problem buried here with the way stl::vector grows... + typeHandlers_.resize(slot); if (!handler(slot)) handler(slot).reset (new MemoryManager (type)); diff --git a/src/lib/allocationcluster.hpp b/src/lib/allocationcluster.hpp index 473ff8cd1..05226ef0a 100644 --- a/src/lib/allocationcluster.hpp +++ b/src/lib/allocationcluster.hpp @@ -55,6 +55,7 @@ #include "common/error.hpp" //#include "common/util.hpp" #include "lib/scopedholder.hpp" +#include "lib/scopedholdertransfer.hpp" @@ -75,11 +76,11 @@ namespace lib { * aren't used after shutting down a given AllocationCluster. */ class AllocationCluster + : boost::noncopyable { public: AllocationCluster (); - AllocationCluster (const AllocationCluster&); ~AllocationCluster () throw(); template @@ -157,7 +158,8 @@ namespace lib { typedef ScopedPtrHolder HMemManager; - typedef std::vector ManagerTable; + typedef Allocator_TransferNoncopyable Allo; + typedef std::vector ManagerTable; ManagerTable typeHandlers_; HMemManager& @@ -208,29 +210,19 @@ namespace lib { static size_t id_; ///< table pos of the memory manager in charge for type TY static size_t & - get() //ManagerTable& handlers) + get() { - //ENSURE (id_ < handlers.size() || 1 <= handlers.size()); // 0th Element used as "undefined" marker - - return id_; //handlers[id_ guard SIDEEFFECT; if (!id_) id_= ++maxTypeIDs; -// if (id_ >= handlers.size()) -// for (size_t idx=handlers.size(); idx()); ////////////////////////////////////////TODO calls ~MemoryManager() but shouldn't -// if (!handlers[id_]) -// { - TY* type_hint(0); - TypeInfo info (type_hint); - return info; -// handlers[id_].reset (setupMemoryManager (info)); ////////////////////////////////////////TODO calls ~MemoryManager() but shouldn't -// } + + return TypeInfo ((TY*) 0 ); } static void @@ -255,9 +247,6 @@ namespace lib { inline void* AllocationCluster::allocation() { -// if (!TypeSlot::get (typeHandlers_)) -// TypeSlot::setup (typeHandlers_); -// return initiateAlloc (TypeSlot::get (typeHandlers_)); void *mem = initiateAlloc (TypeSlot::get()); if (!mem) mem = initiateAlloc (TypeSlot::setup(),TypeSlot::get()); @@ -269,8 +258,6 @@ namespace lib { inline TY& AllocationCluster::commit (TY* obj) { -// PMemManager & typeHandler (TypeSlot::get (typeHandlers_)); -// REQUIRE (typeHandler); REQUIRE (obj); finishAlloc (TypeSlot::get(), obj); return *obj;