OpenDDS::DCPS::Dynamic_Cached_Allocator_With_Overflow< ACE_LOCK > Class Template Reference

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

#include <Dynamic_Cached_Allocator_With_Overflow_T.h>

List of all members.

Public Member Functions

 Dynamic_Cached_Allocator_With_Overflow (size_t n_chunks, size_t chunk_size)
 ~Dynamic_Cached_Allocator_With_Overflow (void)
 Clear things up.
void * malloc (size_t nbytes=0)
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 pool_depth (void)
 Return the number of chunks available in the cache.
size_t available ()

Public Attributes

u_long allocs_from_heap_
 number of allocations from the heap.
u_long allocs_from_pool_
 number of allocations from the pool.
u_long frees_to_heap_
 number of frees returned to the heap
u_long frees_to_pool_
 number of frees returned to the pool

Private Attributes

char * pool_
char * last_
 The end of the pool.
ACE_Locked_Free_List< ACE_Cached_Mem_Pool_Node<
char >, ACE_LOCK > 
free_list_
size_t chunk_size_
 Remember the size of our chunks.


Detailed Description

template<class ACE_LOCK>
class OpenDDS::DCPS::Dynamic_Cached_Allocator_With_Overflow< ACE_LOCK >

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

This class enables caching of dynamically allocated, fixed-size chunks. Notice that the chunk_size must be greater than or equal to sizeof (void*) for this to work properly.

This class can be configured flexibly with different types of ACE_LOCK strategies that support the ACE_Thread_Mutex and ACE_Process_Mutex constructor API.


Constructor & Destructor Documentation

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

Create a cached memory pool with n_chunks chunks each with chunk_size size.

template<class ACE_LOCK>
OpenDDS::DCPS::Dynamic_Cached_Allocator_With_Overflow< ACE_LOCK >::~Dynamic_Cached_Allocator_With_Overflow ( void   )  [inline]

Clear things up.


Member Function Documentation

template<class ACE_LOCK>
size_t OpenDDS::DCPS::Dynamic_Cached_Allocator_With_Overflow< ACE_LOCK >::available (  )  [inline]

How many chunks are available at this time.

template<class ACE_LOCK>
virtual void* OpenDDS::DCPS::Dynamic_Cached_Allocator_With_Overflow< 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 ACE_LOCK>
virtual void* OpenDDS::DCPS::Dynamic_Cached_Allocator_With_Overflow< 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 chunk_size, and is otherwise ignored since calloc() always returns a pointer to an item of chunk_size.

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

Return a chunk of memory back to free list cache.

template<class ACE_LOCK>
void* OpenDDS::DCPS::Dynamic_Cached_Allocator_With_Overflow< ACE_LOCK >::malloc ( size_t  nbytes = 0  )  [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 chunk_size, and is otherwise ignored since malloc() always returns a pointer to an item of chunk_size size.

template<class ACE_LOCK>
size_t OpenDDS::DCPS::Dynamic_Cached_Allocator_With_Overflow< ACE_LOCK >::pool_depth ( void   )  [inline]

Return the number of chunks available in the cache.


Member Data Documentation

template<class ACE_LOCK>
u_long OpenDDS::DCPS::Dynamic_Cached_Allocator_With_Overflow< ACE_LOCK >::allocs_from_heap_

number of allocations from the heap.

template<class ACE_LOCK>
u_long OpenDDS::DCPS::Dynamic_Cached_Allocator_With_Overflow< ACE_LOCK >::allocs_from_pool_

number of allocations from the pool.

template<class ACE_LOCK>
size_t OpenDDS::DCPS::Dynamic_Cached_Allocator_With_Overflow< ACE_LOCK >::chunk_size_ [private]

Remember the size of our chunks.

template<class ACE_LOCK>
ACE_Locked_Free_List<ACE_Cached_Mem_Pool_Node<char>, ACE_LOCK> OpenDDS::DCPS::Dynamic_Cached_Allocator_With_Overflow< ACE_LOCK >::free_list_ [private]

Maintain a cached memory free list. We use char as template parameter, although sizeof(char) is usually less than sizeof(void*). Really important is that chunk_size must be greater or equal to sizeof(void*).

template<class ACE_LOCK>
u_long OpenDDS::DCPS::Dynamic_Cached_Allocator_With_Overflow< ACE_LOCK >::frees_to_heap_

number of frees returned to the heap

template<class ACE_LOCK>
u_long OpenDDS::DCPS::Dynamic_Cached_Allocator_With_Overflow< ACE_LOCK >::frees_to_pool_

number of frees returned to the pool

template<class ACE_LOCK>
char* OpenDDS::DCPS::Dynamic_Cached_Allocator_With_Overflow< ACE_LOCK >::last_ [private]

The end of the pool.

template<class ACE_LOCK>
char* OpenDDS::DCPS::Dynamic_Cached_Allocator_With_Overflow< 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:35 2008 for OpenDDS by  doxygen 1.4.7