OpenDDS::DCPS::Cached_Allocator_With_Overflow< T, ACE_LOCK > Class Template Reference

A fixed-size allocator that caches items for quicker access but if the pool is exhausted it will use the heap. More...

#include <Cached_Allocator_With_Overflow_T.h>

List of all members.

Public Member Functions

 Cached_Allocator_With_Overflow (size_t n_chunks)
 ~Cached_Allocator_With_Overflow (void)
 Clear things up.
void * malloc (size_t nbytes=sizeof(T))
virtual void * calloc (size_t, char= '\0')
virtual void * calloc (size_t, size_t, char= '\0')
void free (void *ptr)
 Return a chunk of memory back to free list cache.
size_t available ()

Public Attributes

ACE_Atomic_Op< ACE_Thread_Mutex,
unsigned long > 
allocs_from_heap_
ACE_Atomic_Op< ACE_Thread_Mutex,
unsigned long > 
allocs_from_pool_
ACE_Atomic_Op< ACE_Thread_Mutex,
unsigned long > 
frees_to_heap_
ACE_Atomic_Op< ACE_Thread_Mutex,
unsigned long > 
frees_to_pool_

Private Attributes

char * pool_
char * last_
 The end of the pool.
ACE_Locked_Free_List< ACE_Cached_Mem_Pool_Node<
T >, ACE_LOCK > 
free_list_
 Maintain a cached memory free list.


Detailed Description

template<class T, class ACE_LOCK>
class OpenDDS::DCPS::Cached_Allocator_With_Overflow< T, ACE_LOCK >

A fixed-size allocator that caches items for quicker access but if the pool is exhausted it will use the heap.

This class enables caching of dynamically allocated, fixed-sized classes. Notice that the sizeof (TYPE) must be greater than or equal to sizeof (void*) for this to work properly. If the free list is empty then memory is allocated from the heap. This way the allocations will not fail but may be slower.


Constructor & Destructor Documentation

template<class T, class ACE_LOCK>
OpenDDS::DCPS::Cached_Allocator_With_Overflow< T, ACE_LOCK >::Cached_Allocator_With_Overflow ( size_t  n_chunks  )  [inline]

Create a cached memory pool with n_chunks chunks each with sizeof (TYPE) size.

template<class T, class ACE_LOCK>
OpenDDS::DCPS::Cached_Allocator_With_Overflow< T, ACE_LOCK >::~Cached_Allocator_With_Overflow ( void   )  [inline]

Clear things up.


Member Function Documentation

template<class T, class ACE_LOCK>
size_t OpenDDS::DCPS::Cached_Allocator_With_Overflow< T, ACE_LOCK >::available (  )  [inline]

How many chunks are available at this time.

template<class T, class ACE_LOCK>
virtual void* OpenDDS::DCPS::Cached_Allocator_With_Overflow< T, ACE_LOCK >::calloc ( size_t  ,
size_t  ,
char  = '\0' 
) [inline, virtual]

This method is a no-op and just returns 0 since the free list only works with fixed sized entities.

template<class T, class ACE_LOCK>
virtual void* OpenDDS::DCPS::Cached_Allocator_With_Overflow< T, ACE_LOCK >::calloc ( size_t  ,
char  = '\0' 
) [inline, virtual]

Get a chunk of memory from free list cache, giving them initial_value. Note that nbytes is only checked to make sure that it's less or equal to sizeof T, and is otherwise ignored since calloc() always returns a pointer to an item of sizeof (T).

template<class T, class ACE_LOCK>
void OpenDDS::DCPS::Cached_Allocator_With_Overflow< T, ACE_LOCK >::free ( void *  ptr  )  [inline]

Return a chunk of memory back to free list cache.

template<class T, class ACE_LOCK>
void* OpenDDS::DCPS::Cached_Allocator_With_Overflow< T, ACE_LOCK >::malloc ( size_t  nbytes = sizeof (T)  )  [inline]

Get a chunk of memory from free list cache. Note that nbytes is only checked to make sure that it's less or equal to sizeof T, and is otherwise ignored since malloc() always returns a pointer to an item of sizeof (T).


Member Data Documentation

template<class T, class ACE_LOCK>
ACE_Atomic_Op<ACE_Thread_Mutex, unsigned long> OpenDDS::DCPS::Cached_Allocator_With_Overflow< T, ACE_LOCK >::allocs_from_heap_

template<class T, class ACE_LOCK>
ACE_Atomic_Op<ACE_Thread_Mutex, unsigned long> OpenDDS::DCPS::Cached_Allocator_With_Overflow< T, ACE_LOCK >::allocs_from_pool_

template<class T, class ACE_LOCK>
ACE_Locked_Free_List<ACE_Cached_Mem_Pool_Node<T>, ACE_LOCK> OpenDDS::DCPS::Cached_Allocator_With_Overflow< T, ACE_LOCK >::free_list_ [private]

Maintain a cached memory free list.

template<class T, class ACE_LOCK>
ACE_Atomic_Op<ACE_Thread_Mutex, unsigned long> OpenDDS::DCPS::Cached_Allocator_With_Overflow< T, ACE_LOCK >::frees_to_heap_

template<class T, class ACE_LOCK>
ACE_Atomic_Op<ACE_Thread_Mutex, unsigned long> OpenDDS::DCPS::Cached_Allocator_With_Overflow< T, ACE_LOCK >::frees_to_pool_

template<class T, class ACE_LOCK>
char* OpenDDS::DCPS::Cached_Allocator_With_Overflow< T, ACE_LOCK >::last_ [private]

The end of the pool.

template<class T, class ACE_LOCK>
char* OpenDDS::DCPS::Cached_Allocator_With_Overflow< T, ACE_LOCK >::pool_ [private]

Remember how we allocate the memory in the first place so we can clear things up later.


The documentation for this class was generated from the following file:
Generated on Fri Nov 7 09:37:32 2008 for OpenDDS by  doxygen 1.4.7