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.

FewObjectsRecyclingAllocator FewObjectsRecyclingAllocator FewObjectsRecyclingAllocator

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 ? ()

Methods in detail

FewObjectsRecyclingAllocator ( in FewObjectsRecyclingAllocator other )

copy constructor


FewObjectsRecyclingAllocator ( in Object cloneableSource, in UInt32 maxCountBeforeWarning, in String maxCountWarning )

Constructs a FewObjectsRecyclingAllocator.

cloneableSource The source instance of the object. Allocated objects will be a copy of this one (cloneableSource.clone())
maxCountBeforeWarning Allocated count limit (per thread) after which the maxCountWarning error will be logged
maxCountWarning The error to be logged if the maxCountBeforeWarning allocation limit is reached


FewObjectsRecyclingAllocator ()

default constructor


Ref<Object> FewObjectsRecyclingAllocator.allocate! ()

Returns an allocated object. This object must be released from the same thread by calling FewObjectsRecyclingAllocator.free, otherwise an error will be logged.

Because objects are recycled, it is possible that the returned object is already initialized since it was previously used.


Size FewObjectsRecyclingAllocator.allocatedCount? ()

Returns the total allocated count, for all threads. This excludes instances that are not being used.


FewObjectsRecyclingAllocator FewObjectsRecyclingAllocator.clone? ()

clone method


FewObjectsRecyclingAllocator.free! ( in Ref<Object> reference )

Frees an allocated object by transferring the ownership to the FewObjectsRecyclingAllocator. This object must have been allocated from the same thread by a call to FewObjectsRecyclingAllocator.allocate, otherwise an error will be logged.

This object will not be destroyed, and will be returned by a future call to FewObjectsRecyclingAllocator.allocate for the same thread (recycled).


Size FewObjectsRecyclingAllocator.freeCount? ()

Returns the total unused instances count, for all threads.