OpenDDS::DCPS::BasicQueueLinkAllocator< T > Class Template Reference

#include <BasicQueueLinkAllocator_T.h>

Inheritance diagram for OpenDDS::DCPS::BasicQueueLinkAllocator< T >:

Inheritance graph
[legend]
Collaboration diagram for OpenDDS::DCPS::BasicQueueLinkAllocator< T >:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 BasicQueueLinkAllocator (size_t chunk_size, size_t initial_chunks)
 Constructor.
virtual ~BasicQueueLinkAllocator ()
 Virtual Destructor.
void * malloc (size_t nbytes=sizeof(LinkType))
 malloc implementation.
virtual void * calloc (size_t nbytes=sizeof(LinkType), char initial_value= '\0')
 calloc implementation.
virtual void * calloc (size_t n_elem, size_t elem_size, char initial_value= '\0')
 This interface not supported.
void free (void *ptr)
 free implementation.

Private Types

typedef BasicQueueLink< T > LinkType
typedef BasicQueueLinkChunk<
T > 
ChunkType
typedef ACE_Cached_Mem_Pool_Node<
LinkType
NodeType
typedef ACE_Locked_Free_List<
NodeType, ACE_Null_Mutex > 
FreeListType

Private Member Functions

void grow ()
 Grow by another chunk.

Private Attributes

size_t chunk_size_
 Number of links to allocate for each chunk.
ChunkTypehead_chunk_
 The first chunk.
ChunkTypetail_chunk_
 The last chunk.
FreeListType free_list_
 Maintain a cached memory free list.

Detailed Description

template<typename T>
class OpenDDS::DCPS::BasicQueueLinkAllocator< T >

Definition at line 21 of file BasicQueueLinkAllocator_T.h.


Member Typedef Documentation

template<typename T>
typedef BasicQueueLinkChunk<T> OpenDDS::DCPS::BasicQueueLinkAllocator< T >::ChunkType [private]

Definition at line 25 of file BasicQueueLinkAllocator_T.h.

template<typename T>
typedef ACE_Locked_Free_List<NodeType, ACE_Null_Mutex> OpenDDS::DCPS::BasicQueueLinkAllocator< T >::FreeListType [private]

Definition at line 27 of file BasicQueueLinkAllocator_T.h.

template<typename T>
typedef BasicQueueLink<T> OpenDDS::DCPS::BasicQueueLinkAllocator< T >::LinkType [private]

Definition at line 24 of file BasicQueueLinkAllocator_T.h.

template<typename T>
typedef ACE_Cached_Mem_Pool_Node<LinkType > OpenDDS::DCPS::BasicQueueLinkAllocator< T >::NodeType [private]

Definition at line 26 of file BasicQueueLinkAllocator_T.h.


Constructor & Destructor Documentation

template<typename T>
OpenDDS::DCPS::BasicQueueLinkAllocator< T >::BasicQueueLinkAllocator ( size_t  chunk_size,
size_t  initial_chunks 
) [inline]

Constructor.

Definition at line 32 of file BasicQueueLinkAllocator_T.h.

00033     : chunk_size_(chunk_size),
00034       head_chunk_(0),
00035       tail_chunk_(0),
00036       free_list_(ACE_PURE_FREE_LIST) {
00037     for (size_t i = 0; i < initial_chunks; i++) {
00038       this->grow();
00039     }
00040   }

template<typename T>
virtual OpenDDS::DCPS::BasicQueueLinkAllocator< T >::~BasicQueueLinkAllocator (  )  [inline, virtual]

Virtual Destructor.

Definition at line 43 of file BasicQueueLinkAllocator_T.h.

References OpenDDS::DCPS::BasicQueueLinkAllocator< T >::head_chunk_, and OpenDDS::DCPS::BasicQueueLinkChunk< T >::next_.

00043                                      {
00044     ChunkType* chunk = this->head_chunk_;
00045 
00046     while (chunk != 0) {
00047       ChunkType* next_chunk = chunk->next_;
00048       delete chunk;
00049       chunk = next_chunk;
00050     }
00051   }


Member Function Documentation

template<typename T>
virtual void* OpenDDS::DCPS::BasicQueueLinkAllocator< T >::calloc ( size_t  n_elem,
size_t  elem_size,
char  initial_value = '\0' 
) [inline, virtual]

This interface not supported.

Definition at line 97 of file BasicQueueLinkAllocator_T.h.

00099                                                     {
00100     ACE_UNUSED_ARG(n_elem);
00101     ACE_UNUSED_ARG(elem_size);
00102     ACE_UNUSED_ARG(initial_value);
00103     ACE_NOTSUP_RETURN(0);
00104   }

template<typename T>
virtual void* OpenDDS::DCPS::BasicQueueLinkAllocator< T >::calloc ( size_t  nbytes = sizeof(LinkType),
char  initial_value = '\0' 
) [inline, virtual]

calloc implementation.

Definition at line 74 of file BasicQueueLinkAllocator_T.h.

References OpenDDS::DCPS::BasicQueueLinkAllocator< T >::free_list_, and OpenDDS::DCPS::BasicQueueLinkAllocator< T >::grow().

00075                                                   {
00076     // Check if size requested fits the pre-determined size.
00077     if (nbytes != sizeof(LinkType)) {
00078       return 0;
00079     }
00080 
00081     // addr() call is really not absolutely necessary because
00082     // of the way ACE_Cached_Mem_Pool_Node's internal
00083     // structure is arranged.
00084     void* ptr = this->free_list_.remove()->addr();
00085 
00086     if (ptr == 0) {
00087       this->grow();
00088       ptr = this->free_list_.remove()->addr();
00089     }
00090 
00091     ACE_OS::memset(ptr, initial_value, sizeof(LinkType));
00092 
00093     return ptr;
00094   }

template<typename T>
void OpenDDS::DCPS::BasicQueueLinkAllocator< T >::free ( void *  ptr  )  [inline]

free implementation.

Definition at line 107 of file BasicQueueLinkAllocator_T.h.

References OpenDDS::DCPS::BasicQueueLinkAllocator< T >::free_list_.

00107                        {
00108     this->free_list_.add((NodeType*)ptr);
00109   }

template<typename T>
void OpenDDS::DCPS::BasicQueueLinkAllocator< T >::grow (  )  [inline, private]

Grow by another chunk.

Definition at line 114 of file BasicQueueLinkAllocator_T.h.

References OpenDDS::DCPS::BasicQueueLinkAllocator< T >::chunk_size_, OpenDDS::DCPS::BasicQueueLinkAllocator< T >::head_chunk_, OpenDDS::DCPS::BasicQueueLinkChunk< T >::links_, OpenDDS::DCPS::BasicQueueLinkChunk< T >::next_, and OpenDDS::DCPS::BasicQueueLinkAllocator< T >::tail_chunk_.

Referenced by OpenDDS::DCPS::BasicQueueLinkAllocator< T >::calloc(), and OpenDDS::DCPS::BasicQueueLinkAllocator< T >::malloc().

00114               {
00115     ChunkType* chunk;
00116     ACE_NEW(chunk, ChunkType(this->chunk_size_));
00117 
00118     for (size_t i = 0; i < this->chunk_size_; ++i) {
00119       void* placement = &(chunk->links_[i]);
00120       this->free_list_.add(new(placement) NodeType);
00121     }
00122 
00123     // Add the chunk to the "chunk list".
00124     if (head_chunk_ == 0) {
00125       this->head_chunk_ = this->tail_chunk_ = chunk;
00126 
00127     } else {
00128       this->tail_chunk_->next_ = chunk;
00129       this->tail_chunk_ = chunk;
00130     }
00131   }

template<typename T>
void* OpenDDS::DCPS::BasicQueueLinkAllocator< T >::malloc ( size_t  nbytes = sizeof(LinkType)  )  [inline]

malloc implementation.

Definition at line 54 of file BasicQueueLinkAllocator_T.h.

References OpenDDS::DCPS::BasicQueueLinkAllocator< T >::free_list_, and OpenDDS::DCPS::BasicQueueLinkAllocator< T >::grow().

00054                                                  {
00055     // Check if size requested fits within pre-determined size.
00056     if (nbytes != sizeof(LinkType)) {
00057       return 0;
00058     }
00059 
00060     // addr() call is really not absolutely necessary because
00061     // of the way ACE_Cached_Mem_Pool_Node's internal
00062     // structure is arranged.
00063     void* ptr = this->free_list_.remove()->addr();
00064 
00065     if (ptr == 0) {
00066       this->grow();
00067       ptr = this->free_list_.remove()->addr();
00068     }
00069 
00070     return ptr;
00071   }


Member Data Documentation

template<typename T>
size_t OpenDDS::DCPS::BasicQueueLinkAllocator< T >::chunk_size_ [private]

Number of links to allocate for each chunk.

Definition at line 134 of file BasicQueueLinkAllocator_T.h.

Referenced by OpenDDS::DCPS::BasicQueueLinkAllocator< T >::grow().

template<typename T>
FreeListType OpenDDS::DCPS::BasicQueueLinkAllocator< T >::free_list_ [private]

Maintain a cached memory free list.

Definition at line 143 of file BasicQueueLinkAllocator_T.h.

Referenced by OpenDDS::DCPS::BasicQueueLinkAllocator< T >::calloc(), OpenDDS::DCPS::BasicQueueLinkAllocator< T >::free(), and OpenDDS::DCPS::BasicQueueLinkAllocator< T >::malloc().

template<typename T>
ChunkType* OpenDDS::DCPS::BasicQueueLinkAllocator< T >::head_chunk_ [private]

The first chunk.

Definition at line 137 of file BasicQueueLinkAllocator_T.h.

Referenced by OpenDDS::DCPS::BasicQueueLinkAllocator< T >::grow(), and OpenDDS::DCPS::BasicQueueLinkAllocator< T >::~BasicQueueLinkAllocator().

template<typename T>
ChunkType* OpenDDS::DCPS::BasicQueueLinkAllocator< T >::tail_chunk_ [private]

The last chunk.

Definition at line 140 of file BasicQueueLinkAllocator_T.h.

Referenced by OpenDDS::DCPS::BasicQueueLinkAllocator< T >::grow().


The documentation for this class was generated from the following file:
Generated on Fri Feb 12 20:06:26 2016 for OpenDDS by  doxygen 1.4.7