FewObjectsRecyclingAllocator.kl

Types

FewObjectsRecyclingAllocator (object)

The FewObjectsRecyclingAllocator is a simple per-thread allocator that simply allocates and recycles objects of a given type using a thread local pool.

This allows to efficiently allocate thread-specific objects by avoiding locking. These objects are recycled and never released, in order to lower heap allocation overhead. Consequently, the FewObjectsRecyclingAllocator should be used for objects that use a relatively small amount of memory. Because objects are recycled, it is possible that allocated objects are already initialized since they might have been used before. Also, it is required that objects get released from the same thread that they were allocated, otherwise an error will be logged.

In order to detect potential leaking errors, the maxCountBeforeWarning constructor parameter allows to specify a per-thread allocation count limit after which an error message will get printed.

Members

UInt32 maxCountBeforeWarning allocated count limit (per thread) after which an error will be logged
String maxCountWarning the error to be logged if the maxCountBeforeWarning allocation limit is reached

Methods

  FewObjectsRecyclingAllocator ( in FewObjectsRecyclingAllocator other )
  FewObjectsRecyclingAllocator ( in Object cloneableSource, in UInt32 maxCountBeforeWarning, in String maxCountWarning )
  FewObjectsRecyclingAllocator ()
Ref<Object> allocate ! ()
Size allocatedCount ? ()
FewObjectsRecyclingAllocator clone ? ()
  free ! ( in Ref<Object> reference )
Size freeCount ? ()