UCommon
ucommon::array_reuse< T > Class Template Reference

An array of reusable types. More...

#include <reuse.h>

Inheritance diagram for ucommon::array_reuse< T >:
Collaboration diagram for ucommon::array_reuse< T >:

Public Member Functions

 array_reuse (unsigned count)
 Create private heap of reusable objects of specified type.
 
 array_reuse (unsigned count, void *memory)
 Create reusable objects of specific type in preallocated memory.
 
T * create (timeout_t timeout)
 Create a typed object from the heap.
 
T * create (void)
 Create a typed object from the heap.
 
T * get (timeout_t timeout)
 Get a typed object from the heap.
 
T * get (void)
 Get a typed object from the heap.
 
 operator bool () const
 Test if typed objects available in heap or re-use list.
 
 operator T* ()
 Get a typed object from the heap by type casting reference.
 
bool operator! () const
 Test if the entire heap has been allocated.
 
T * operator* ()
 Get a typed object from the heap by pointer reference.
 
void release (T *object)
 Release (return) a typed object back to the heap for re-use.
 
T * request (void)
 Request immediately next available typed object from the heap.
 

Additional Inherited Members

- Protected Member Functions inherited from ucommon::ArrayReuse
 ArrayReuse (size_t objsize, unsigned c)
 
 ArrayReuse (size_t objsize, unsigned c, void *memory)
 
bool avail (void) const
 
ReusableObjectget (timeout_t timeout)
 
ReusableObjectget (void)
 
ReusableObjectrequest (void)
 
 ~ArrayReuse ()
 Destroy reusable private heap array.
 
- Protected Member Functions inherited from ucommon::ReusableAllocator
ReusableObjectnext (ReusableObject *object)
 Get next reusable object in the pool.
 
void release (ReusableObject *object)
 Release resuable object.
 
 ReusableAllocator ()
 Initialize reusable allocator through a conditional.
 
- Protected Member Functions inherited from ucommon::Conditional
void broadcast (void)
 Signal the conditional to release all waiting threads.
 
 Conditional ()
 Initialize and construct conditional.
 
void signal (void)
 Signal the conditional to release one waiting thread.
 
bool wait (struct timespec *timeout)
 Conditional wait for signal on timespec timeout.
 
bool wait (timeout_t timeout)
 Conditional wait for signal on millisecond timeout.
 
void wait (void)
 Wait (block) until signalled.
 
 ~Conditional ()
 Destroy conditional, release any blocked threads.
 
- Protected Member Functions inherited from ucommon::ConditionMutex
 ConditionMutex ()
 Initialize and construct conditional.
 
void lock (void)
 Lock the conditional's supporting mutex.
 
void unlock (void)
 Unlock the conditional's supporting mutex.
 
 ~ConditionMutex ()
 Destroy conditional, release any blocked threads.
 
- Static Protected Member Functions inherited from ucommon::Conditional
static pthread_condattr_t * initializer (void)
 Support function for getting conditional attributes for realtime scheduling.
 
static void set (struct timespec *hires, timeout_t timeout)
 Convert a millisecond timeout into use for high resolution conditional timers.
 
- Protected Attributes inherited from ucommon::ReusableAllocator
ReusableObjectfreelist
 
unsigned waiting
 
- Protected Attributes inherited from ucommon::Conditional
pthread_cond_t cond
 
- Protected Attributes inherited from ucommon::ConditionMutex
pthread_mutex_t mutex
 
- Static Protected Attributes inherited from ucommon::Conditional
static attribute attr
 

Detailed Description

template<class T>
class ucommon::array_reuse< T >

An array of reusable types.

A pool of typed objects is created which can be allocated as needed. Deallocated typed objects are returned to the pool so they can be reallocated later. This is a private fixed size heap.

Author
David Sugar dyfet.nosp@m.@gnu.nosp@m.telep.nosp@m.hony.nosp@m..org

Definition at line 104 of file reuse.h.

Constructor & Destructor Documentation

◆ array_reuse() [1/2]

template<class T >
ucommon::array_reuse< T >::array_reuse ( unsigned count)
inline

Create private heap of reusable objects of specified type.

Parameters
countof objects of specified type to allocate.

Definition at line 114 of file reuse.h.

◆ array_reuse() [2/2]

template<class T >
ucommon::array_reuse< T >::array_reuse ( unsigned count,
void * memory )
inline

Create reusable objects of specific type in preallocated memory.

Parameters
countof objects of specified type in memory.
memoryto use.

Definition at line 122 of file reuse.h.

Member Function Documentation

◆ create() [1/2]

template<class T >
T * ucommon::array_reuse< T >::create ( timeout_t timeout)
inline

Create a typed object from the heap.

This function blocks until the the heap has an object to return or the timer has expired.

Parameters
timeoutto wait for heap in milliseconds.
Returns
typed object pointer from heap or NULL if timeout.

Definition at line 183 of file reuse.h.

Here is the call graph for this function:

◆ create() [2/2]

template<class T >
T * ucommon::array_reuse< T >::create ( void )
inline

Create a typed object from the heap.

This function blocks when the heap is empty until an object is returned to the heap.

Returns
typed object pointer from heap.

Definition at line 163 of file reuse.h.

Here is the call graph for this function:

◆ get() [1/2]

template<class T >
T * ucommon::array_reuse< T >::get ( timeout_t timeout)
inline

Get a typed object from the heap.

This function blocks until the the heap has an object to return or the timer has expired.

Parameters
timeoutto wait for heap in milliseconds.
Returns
typed object pointer from heap or NULL if timeout.

Definition at line 173 of file reuse.h.

◆ get() [2/2]

template<class T >
T * ucommon::array_reuse< T >::get ( void )
inline

Get a typed object from the heap.

This function blocks when the heap is empty until an object is returned to the heap.

Returns
typed object pointer from heap.

Definition at line 154 of file reuse.h.

◆ operator bool()

template<class T >
ucommon::array_reuse< T >::operator bool ( ) const
inline

Test if typed objects available in heap or re-use list.

Returns
true if objects still are available.

Definition at line 129 of file reuse.h.

◆ operator T*()

template<class T >
ucommon::array_reuse< T >::operator T* ( )
inline

Get a typed object from the heap by type casting reference.

This function blocks while the heap is empty.

Returns
typed object pointer from heap.

Definition at line 200 of file reuse.h.

Here is the call graph for this function:

◆ operator!()

template<class T >
bool ucommon::array_reuse< T >::operator! ( ) const
inline

Test if the entire heap has been allocated.

Returns
true if no objects are available.

Definition at line 137 of file reuse.h.

◆ operator*()

template<class T >
T * ucommon::array_reuse< T >::operator* ( )
inline

Get a typed object from the heap by pointer reference.

This function blocks while the heap is empty.

Returns
typed object pointer from heap.

Definition at line 209 of file reuse.h.

Here is the call graph for this function:

◆ release()

template<class T >
void ucommon::array_reuse< T >::release ( T * object)
inline

Release (return) a typed object back to the heap for re-use.

Parameters
objectto return.

Definition at line 191 of file reuse.h.

Here is the call graph for this function:

◆ request()

template<class T >
T * ucommon::array_reuse< T >::request ( void )
inline

Request immediately next available typed object from the heap.

Returns
typed object pointer or NULL if heap is empty.

Definition at line 145 of file reuse.h.


The documentation for this class was generated from the following file: