Lumiera  0.pre.03
»edit your freedom«
typed-allocation-manager.hpp File Reference

Go to the source code of this file.

Description

Abstract foundation for building custom allocation managers.

Currently (as of 8/09) this is a draft, factored out of the command-registry. The expectation is that we'll face several similar situations, and thus it would be good to build up a common set of operations and behaviour.

Todo:
WIP WIP.
Concept Summary
The idea is rather to tie the memory manager to a very specific usage situation, then to provide a general-purpose allocator to be used by any instance of a given type. Typically, the goal is to handle memory management for an index or registry, holding implementation objects to be shielded from the client code. Moreover, we'll have to deal with families of types rather then with individual types; usually there will be some common or combined handling for all family members.

The intention is for this TypedAllocationManager template to be used both as a base class providing the implementation skeleton for the actual custom allocation manager, and as an abstract interface, which can be forwarded to the implementation classes in case there is some cooperation required to get the allocation done (for example, there might be some type erasure involved, leaving the (otherwise opaque) implementation class as the only entity with a limited knowledge about the actual memory layout, and thus the only way of creating a clone properly would be to forward down into this implementation class).

Thus, TypedAllocationManager provides the classical operations of an allocator

  • allocate
  • construct
  • deallocate But each of these operations is to be invoked in a typed context. Besides, 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!
Warning
this quick-n-dirty heap allocation might produce misaligned storage!!
See also
CommandRegistry
AllocationCluster (another custom allocation scheme, which could be united)

Definition in file typed-allocation-manager.hpp.

#include "lib/error.hpp"
#include "lib/meta/util.hpp"
#include "lib/typed-counter.hpp"
#include "include/logging.h"
#include <utility>
#include <memory>

Classes

class  TypedAllocationManager::Killer< XOX >
 opaque link to the manager, to be used by handles and smart-ptrs to trigger preconfigured destruction. More...
 
struct  TypedAllocationManager::Slot< XOX >
 a token representing a newly opened slot capable for holding an object of type XOX . More...
 
class  TypedAllocationManager
 Foundation for a custom allocation manager, tracking the created objects by smart-ptrs. More...
 

Namespaces

 lib
 Implementation namespace for support and library code.