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

Go to the source code of this file.

Description

Creating series of type-based contexts.

The idea is to get a "slot" for any given type, so we can build tables or families of implementations based on these types. Each of those "slots" can be addressed by a distinct (compile time) type, but at the same time holds a numeric ID (runtime assigned on demand). This setup allows to bridge between metaprogramming and (runtime) dispatcher tables.

Each such series of type-id-slots is associated to a distinct usage context. Those usage contexts are discerned by the template parameter CX. Each of these usage contexts uses a separate numbering scheme on his own, i.e. every new type encountered at runtime gets the next higher ID number (slot).

Warning
the actual ID numbers depend on the sequence of first encountering a given type. If this sequence isn't reproducible between runs, then also the generated type-IDs aren't reproducible. Thus its advisable not to rely on any specific numeric value here, but always just access the service through the type slots.
Note
Locking is based on a class lock per usage context, but a lock needs only be acquired to allocate a new ID number (double checked locking). Thus lock contention is considered not to be a problem, yet we need actually to verify this by real measurements (as of 2011)
Todo:
2010 ... this is the first, preliminary version of a facility, which is expected to get quite important for custom allocation management.
Remarks
in 2023 changed partially to use atomics; measurements indicate however that the impact of locking technology is negligible. In concurrent use, the wait times are dominating. In single threaded use, both using Atomics or a nonrecursive mutex yield amortised invocation times around 60ns.
See also
typed-counter-test.cpp
TypedAllocationManager
AllocationCluster (custom allocation scheme using a similar idea inline)

Definition in file typed-counter.hpp.

#include "lib/error.hpp"
#include "lib/sync-classlock.hpp"
#include <atomic>
#include <string>
#include <deque>

Classes

class  FamilyMember< TY >
 Utility to produce member IDs for objects belonging to a "Family", as defined by a distinguishing type. More...
 
class  TypedContext< CX >::ID< TY >
 type-ID More...
 
class  TypedContext< CX >
 Provide type-IDs for a specific context. More...
 
class  TypedCounter
 Utility providing a set of counters, each tied to a specific type. More...
 

Typedefs

typedef size_t IxID
 

Functions

string showSize (size_t val) noexcept
 

Namespaces

 lib
 Implementation namespace for support and library code.