OpenDDS::DCPS::FirstTimeFastAllocator< T, N > Class Template Reference

#include <ZeroCopyAllocator_T.h>

Inheritance diagram for OpenDDS::DCPS::FirstTimeFastAllocator< T, N >:

Inheritance graph
[legend]
Collaboration diagram for OpenDDS::DCPS::FirstTimeFastAllocator< T, N >:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 FirstTimeFastAllocator ()
virtual void * malloc (size_t nbytes)
virtual void free (void *ptr)
virtual void * calloc (size_t nbytes, char initial_value= '\0')
 These methods are no-ops.
virtual void * calloc (size_t n_elem, size_t elem_size, char initial_value= '\0')
virtual int remove ()
virtual int bind (const char *name, void *pointer, int duplicates=0)
virtual int trybind (const char *name, void *&pointer)
virtual int find (const char *name, void *&pointer)
virtual int find (const char *name)
virtual int unbind (const char *name)
virtual int unbind (const char *name, void *&pointer)
virtual int sync (ssize_t len=-1, int flags=MS_SYNC)
virtual int sync (void *addr, size_t len, int flags=MS_SYNC)
virtual int protect (ssize_t len=-1, int prot=PROT_RDWR)
virtual int protect (void *addr, size_t len, int prot=PROT_RDWR)
virtual void dump () const
T * pool ()

Private Attributes

bool firstTime_
 is this the first time this is allocated?
pool_ [N]
 the pool of allocated memory.

Detailed Description

template<class T, std::size_t N>
class OpenDDS::DCPS::FirstTimeFastAllocator< T, N >

This allocator is "Fast" because it's pool can be on the stack (If the object is on the stack and hence it does not require the cost of allocating and deallocating on the heap. It object is on the heap then it requires just one allocation; not two.)
Warning:
The object using this allocator must not have a scope smaller than this object !!!

Definition at line 28 of file ZeroCopyAllocator_T.h.


Constructor & Destructor Documentation

template<class T, std::size_t N>
ACE_INLINE OpenDDS::DCPS::FirstTimeFastAllocator< T, N >::FirstTimeFastAllocator (  ) 

Definition at line 12 of file ZeroCopyAllocator_T.inl.

00013   : firstTime_(true)
00014 {
00015 }


Member Function Documentation

template<class T, std::size_t N>
int OpenDDS::DCPS::FirstTimeFastAllocator< T, N >::bind ( const char *  name,
void *  pointer,
int  duplicates = 0 
) [virtual]

Definition at line 57 of file ZeroCopyAllocator_T.cpp.

00058 {/* no-op */
00059   ACE_ERROR((LM_ERROR,
00060              ACE_TEXT("(%P|%t) %T not supported %a\n"))) ;
00061   ACE_UNUSED_ARG(name);
00062   ACE_UNUSED_ARG(pointer);
00063   ACE_UNUSED_ARG(duplicates);
00064   return -1;
00065 }

template<class T, std::size_t N>
void * OpenDDS::DCPS::FirstTimeFastAllocator< T, N >::calloc ( size_t  n_elem,
size_t  elem_size,
char  initial_value = '\0' 
) [virtual]

Definition at line 38 of file ZeroCopyAllocator_T.cpp.

00039 {/* no-op */
00040   ACE_UNUSED_ARG(n_elem);
00041   ACE_UNUSED_ARG(elem_size);
00042   ACE_UNUSED_ARG(initial_value);
00043   return (void*)0;
00044 }

template<class T, std::size_t N>
void * OpenDDS::DCPS::FirstTimeFastAllocator< T, N >::calloc ( size_t  nbytes,
char  initial_value = '\0' 
) [virtual]

These methods are no-ops.

Definition at line 29 of file ZeroCopyAllocator_T.cpp.

00030 {/* no-op */
00031   ACE_UNUSED_ARG(nbytes);
00032   ACE_UNUSED_ARG(initial_value);
00033   return (void*)0;
00034 }

template<class T, std::size_t N>
void OpenDDS::DCPS::FirstTimeFastAllocator< T, N >::dump (  )  const [virtual]

Definition at line 179 of file ZeroCopyAllocator_T.cpp.

00180 {/* no-op */
00181   ACE_ERROR((LM_ERROR,
00182              ACE_TEXT("(%P|%t) %T not supported %a\n"))) ;
00183 }

template<class T, std::size_t N>
int OpenDDS::DCPS::FirstTimeFastAllocator< T, N >::find ( const char *  name  )  [virtual]

Definition at line 91 of file ZeroCopyAllocator_T.cpp.

00092 {/* no-op */
00093   ACE_ERROR((LM_ERROR,
00094              ACE_TEXT("(%P|%t) %T not supported %a\n"))) ;
00095   ACE_UNUSED_ARG(name);
00096   return -1;
00097 }

template<class T, std::size_t N>
int OpenDDS::DCPS::FirstTimeFastAllocator< T, N >::find ( const char *  name,
void *&  pointer 
) [virtual]

Definition at line 80 of file ZeroCopyAllocator_T.cpp.

00081 {/* no-op */
00082   ACE_ERROR((LM_ERROR,
00083              ACE_TEXT("(%P|%t) %T not supported %a\n"))) ;
00084   ACE_UNUSED_ARG(name);
00085   ACE_UNUSED_ARG(pointer);
00086   return -1;
00087 }

template<class T, std::size_t N>
ACE_INLINE void OpenDDS::DCPS::FirstTimeFastAllocator< T, N >::free ( void *  ptr  )  [virtual]

Definition at line 36 of file ZeroCopyAllocator_T.inl.

References OpenDDS::DCPS::FirstTimeFastAllocator< T, N >::pool_.

00037 {
00038   if (ptr != (void*) pool_) {
00039 #if defined (ACE_HAS_ALLOC_HOOKS)
00040      ACE_Allocator::instance()->free(ptr);
00041 #else
00042     ACE_OS::free(ptr);
00043 #endif /* ACE_HAS_ALLOC_HOOKS */
00044   }
00045 }

template<class T, std::size_t N>
ACE_INLINE void * OpenDDS::DCPS::FirstTimeFastAllocator< T, N >::malloc ( size_t  nbytes  )  [virtual]

Definition at line 19 of file ZeroCopyAllocator_T.inl.

References OpenDDS::DCPS::FirstTimeFastAllocator< T, N >::firstTime_, and OpenDDS::DCPS::FirstTimeFastAllocator< T, N >::pool_.

00020 {
00021   if (firstTime_ && nbytes <= N * sizeof(T)) {
00022     firstTime_ = false;
00023     return (void*) pool_;
00024 
00025   } else {
00026 #if defined (ACE_HAS_ALLOC_HOOKS)
00027     return ACE_Allocator::instance()->malloc(nbytes);
00028 #else
00029     return ACE_OS::malloc(nbytes);
00030 #endif /* ACE_HAS_ALLOC_HOOKS */
00031   }
00032 }

template<class T, std::size_t N>
T* OpenDDS::DCPS::FirstTimeFastAllocator< T, N >::pool (  )  [inline]

Definition at line 53 of file ZeroCopyAllocator_T.h.

Referenced by TAO::DCPS::ZeroCopyDataSeq< Sample_T, DEF_MAX >::swap().

00053             {
00054     return pool_;
00055   }

template<class T, std::size_t N>
int OpenDDS::DCPS::FirstTimeFastAllocator< T, N >::protect ( void *  addr,
size_t  len,
int  prot = PROT_RDWR 
) [virtual]

Definition at line 156 of file ZeroCopyAllocator_T.cpp.

00157 {/* no-op */
00158   ACE_ERROR((LM_ERROR,
00159              ACE_TEXT("(%P|%t) %T not supported %a\n"))) ;
00160   ACE_UNUSED_ARG(addr);
00161   ACE_UNUSED_ARG(len);
00162   ACE_UNUSED_ARG(prot);
00163   return -1;
00164 }

template<class T, std::size_t N>
int OpenDDS::DCPS::FirstTimeFastAllocator< T, N >::protect ( ssize_t  len = -1,
int  prot = PROT_RDWR 
) [virtual]

Definition at line 145 of file ZeroCopyAllocator_T.cpp.

00146 {/* no-op */
00147   ACE_ERROR((LM_ERROR,
00148              ACE_TEXT("(%P|%t) %T not supported %a\n"))) ;
00149   ACE_UNUSED_ARG(len);
00150   ACE_UNUSED_ARG(prot);
00151   return -1;
00152 }

template<class T, std::size_t N>
int OpenDDS::DCPS::FirstTimeFastAllocator< T, N >::remove (  )  [virtual]

Definition at line 48 of file ZeroCopyAllocator_T.cpp.

00049 {/* no-op */
00050   ACE_ERROR((LM_ERROR,
00051              ACE_TEXT("(%P|%t) %T not supported %a\n"))) ;
00052   return -1;
00053 }

template<class T, std::size_t N>
int OpenDDS::DCPS::FirstTimeFastAllocator< T, N >::sync ( void *  addr,
size_t  len,
int  flags = MS_SYNC 
) [virtual]

Definition at line 133 of file ZeroCopyAllocator_T.cpp.

00134 {/* no-op */
00135   ACE_ERROR((LM_ERROR,
00136              ACE_TEXT("(%P|%t) %T not supported %a\n"))) ;
00137   ACE_UNUSED_ARG(addr);
00138   ACE_UNUSED_ARG(len);
00139   ACE_UNUSED_ARG(flags);
00140   return -1;
00141 }

template<class T, std::size_t N>
int OpenDDS::DCPS::FirstTimeFastAllocator< T, N >::sync ( ssize_t  len = -1,
int  flags = MS_SYNC 
) [virtual]

Definition at line 122 of file ZeroCopyAllocator_T.cpp.

00123 {/* no-op */
00124   ACE_ERROR((LM_ERROR,
00125              ACE_TEXT("(%P|%t) %T not supported %a\n"))) ;
00126   ACE_UNUSED_ARG(len);
00127   ACE_UNUSED_ARG(flags);
00128   return -1;
00129 }

template<class T, std::size_t N>
int OpenDDS::DCPS::FirstTimeFastAllocator< T, N >::trybind ( const char *  name,
void *&  pointer 
) [virtual]

Definition at line 69 of file ZeroCopyAllocator_T.cpp.

00070 {/* no-op */
00071   ACE_ERROR((LM_ERROR,
00072              ACE_TEXT("(%P|%t) %T not supported %a\n"))) ;
00073   ACE_UNUSED_ARG(name);
00074   ACE_UNUSED_ARG(pointer);
00075   return -1;
00076 }

template<class T, std::size_t N>
int OpenDDS::DCPS::FirstTimeFastAllocator< T, N >::unbind ( const char *  name,
void *&  pointer 
) [virtual]

Definition at line 111 of file ZeroCopyAllocator_T.cpp.

00112 {/* no-op */
00113   ACE_ERROR((LM_ERROR,
00114              ACE_TEXT("(%P|%t) %T not supported %a\n"))) ;
00115   ACE_UNUSED_ARG(name);
00116   ACE_UNUSED_ARG(pointer);
00117   return -1;
00118 }

template<class T, std::size_t N>
int OpenDDS::DCPS::FirstTimeFastAllocator< T, N >::unbind ( const char *  name  )  [virtual]

Definition at line 101 of file ZeroCopyAllocator_T.cpp.

00102 {/* no-op */
00103   ACE_ERROR((LM_ERROR,
00104              ACE_TEXT("(%P|%t) %T not supported %a\n"))) ;
00105   ACE_UNUSED_ARG(name);
00106   return -1;
00107 }


Member Data Documentation

template<class T, std::size_t N>
bool OpenDDS::DCPS::FirstTimeFastAllocator< T, N >::firstTime_ [private]

is this the first time this is allocated?

Definition at line 59 of file ZeroCopyAllocator_T.h.

Referenced by OpenDDS::DCPS::FirstTimeFastAllocator< T, N >::malloc().

template<class T, std::size_t N>
T OpenDDS::DCPS::FirstTimeFastAllocator< T, N >::pool_[N] [private]

the pool of allocated memory.

Definition at line 62 of file ZeroCopyAllocator_T.h.

Referenced by OpenDDS::DCPS::FirstTimeFastAllocator< T, N >::free(), OpenDDS::DCPS::FirstTimeFastAllocator< T, N >::malloc(), and OpenDDS::DCPS::FirstTimeFastAllocator< OpenDDS::DCPS::ReceivedDataElement *, DEF_MAX >::pool().


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