OpenDDS  Snapshot(2023/04/07-19:43)
Public Member Functions | Private Attributes | List of all members
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]

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. More...
 
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 ()
 
- Public Member Functions inherited from ACE_Allocator
 ACE_Allocator (void)
 
virtual ~ACE_Allocator (void)
 

Private Attributes

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

Additional Inherited Members

- Public Types inherited from ACE_Allocator
typedef size_t size_type
 
- Static Public Member Functions inherited from ACE_Allocator
static ACE_Allocatorinstance (void)
 
static ACE_Allocatorinstance (ACE_Allocator *)
 
static void close_singleton (void)
 

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 32 of file ZeroCopyAllocator_T.h.

Constructor & Destructor Documentation

◆ FirstTimeFastAllocator()

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

Definition at line 19 of file ZeroCopyAllocator_T.inl.

20  : firstTime_(true)
21  , pool_()
22 {
23 }
T pool_[N]
the pool of allocated memory.
bool firstTime_
is this the first time this is allocated?

Member Function Documentation

◆ bind()

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

Implements ACE_Allocator.

Definition at line 59 of file ZeroCopyAllocator_T.cpp.

60 {/* no-op */
61  ACE_ERROR((LM_ERROR,
62  ACE_TEXT("(%P|%t) %T not supported %a\n"))) ;
63  ACE_UNUSED_ARG(name);
64  ACE_UNUSED_ARG(pointer);
65  ACE_UNUSED_ARG(duplicates);
66  return -1;
67 }
#define ACE_ERROR(X)
const char *const name
Definition: debug.cpp:60
ACE_TEXT("TCP_Factory")

◆ calloc() [1/2]

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.

Implements ACE_Allocator.

Definition at line 31 of file ZeroCopyAllocator_T.cpp.

32 {/* no-op */
33  ACE_UNUSED_ARG(nbytes);
34  ACE_UNUSED_ARG(initial_value);
35  return (void*)0;
36 }

◆ calloc() [2/2]

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

Implements ACE_Allocator.

Definition at line 40 of file ZeroCopyAllocator_T.cpp.

41 {/* no-op */
42  ACE_UNUSED_ARG(n_elem);
43  ACE_UNUSED_ARG(elem_size);
44  ACE_UNUSED_ARG(initial_value);
45  return (void*)0;
46 }

◆ dump()

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

Implements ACE_Allocator.

Definition at line 181 of file ZeroCopyAllocator_T.cpp.

182 {/* no-op */
183  ACE_ERROR((LM_ERROR,
184  ACE_TEXT("(%P|%t) %T not supported %a\n"))) ;
185 }
#define ACE_ERROR(X)
ACE_TEXT("TCP_Factory")

◆ find() [1/2]

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

Implements ACE_Allocator.

Definition at line 82 of file ZeroCopyAllocator_T.cpp.

83 {/* no-op */
84  ACE_ERROR((LM_ERROR,
85  ACE_TEXT("(%P|%t) %T not supported %a\n"))) ;
86  ACE_UNUSED_ARG(name);
87  ACE_UNUSED_ARG(pointer);
88  return -1;
89 }
#define ACE_ERROR(X)
const char *const name
Definition: debug.cpp:60
ACE_TEXT("TCP_Factory")

◆ find() [2/2]

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

Implements ACE_Allocator.

Definition at line 93 of file ZeroCopyAllocator_T.cpp.

94 {/* no-op */
95  ACE_ERROR((LM_ERROR,
96  ACE_TEXT("(%P|%t) %T not supported %a\n"))) ;
97  ACE_UNUSED_ARG(name);
98  return -1;
99 }
#define ACE_ERROR(X)
const char *const name
Definition: debug.cpp:60
ACE_TEXT("TCP_Factory")

◆ free()

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

Implements ACE_Allocator.

Definition at line 47 of file ZeroCopyAllocator_T.inl.

48 {
49  if (ptr != (void*) pool_) {
50 #if defined (ACE_HAS_ALLOC_HOOKS)
52 #else
53  ACE_OS::free(ptr);
54 #endif /* ACE_HAS_ALLOC_HOOKS */
55  }
56 }
void free(void *)
virtual void free(void *ptr)=0
static ACE_Allocator * instance(void)
T pool_[N]
the pool of allocated memory.

◆ malloc()

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

Implements ACE_Allocator.

Definition at line 30 of file ZeroCopyAllocator_T.inl.

31 {
32  if (firstTime_ && nbytes <= N * sizeof(T)) {
33  firstTime_ = false;
34  return (void*) pool_;
35 
36  } else {
37 #if defined (ACE_HAS_ALLOC_HOOKS)
38  return ACE_Allocator::instance()->malloc(nbytes);
39 #else
40  return ACE_OS::malloc(nbytes);
41 #endif /* ACE_HAS_ALLOC_HOOKS */
42  }
43 }
void * malloc(size_t)
static ACE_Allocator * instance(void)
T pool_[N]
the pool of allocated memory.
bool firstTime_
is this the first time this is allocated?
virtual void * malloc(size_type nbytes)=0

◆ pool()

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

Definition at line 57 of file ZeroCopyAllocator_T.h.

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

57  {
58  return pool_;
59  }
T pool_[N]
the pool of allocated memory.

◆ protect() [1/2]

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

Implements ACE_Allocator.

Definition at line 147 of file ZeroCopyAllocator_T.cpp.

148 {/* no-op */
149  ACE_ERROR((LM_ERROR,
150  ACE_TEXT("(%P|%t) %T not supported %a\n"))) ;
151  ACE_UNUSED_ARG(len);
152  ACE_UNUSED_ARG(prot);
153  return -1;
154 }
#define ACE_ERROR(X)
ACE_TEXT("TCP_Factory")

◆ protect() [2/2]

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

Implements ACE_Allocator.

Definition at line 158 of file ZeroCopyAllocator_T.cpp.

159 {/* no-op */
160  ACE_ERROR((LM_ERROR,
161  ACE_TEXT("(%P|%t) %T not supported %a\n"))) ;
162  ACE_UNUSED_ARG(addr);
163  ACE_UNUSED_ARG(len);
164  ACE_UNUSED_ARG(prot);
165  return -1;
166 }
#define ACE_ERROR(X)
ACE_TEXT("TCP_Factory")

◆ remove()

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

Implements ACE_Allocator.

Definition at line 50 of file ZeroCopyAllocator_T.cpp.

51 {/* no-op */
52  ACE_ERROR((LM_ERROR,
53  ACE_TEXT("(%P|%t) %T not supported %a\n"))) ;
54  return -1;
55 }
#define ACE_ERROR(X)
ACE_TEXT("TCP_Factory")

◆ sync() [1/2]

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

Implements ACE_Allocator.

Definition at line 124 of file ZeroCopyAllocator_T.cpp.

125 {/* no-op */
126  ACE_ERROR((LM_ERROR,
127  ACE_TEXT("(%P|%t) %T not supported %a\n"))) ;
128  ACE_UNUSED_ARG(len);
129  ACE_UNUSED_ARG(flags);
130  return -1;
131 }
#define ACE_ERROR(X)
ACE_TEXT("TCP_Factory")

◆ sync() [2/2]

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

Implements ACE_Allocator.

Definition at line 135 of file ZeroCopyAllocator_T.cpp.

136 {/* no-op */
137  ACE_ERROR((LM_ERROR,
138  ACE_TEXT("(%P|%t) %T not supported %a\n"))) ;
139  ACE_UNUSED_ARG(addr);
140  ACE_UNUSED_ARG(len);
141  ACE_UNUSED_ARG(flags);
142  return -1;
143 }
#define ACE_ERROR(X)
ACE_TEXT("TCP_Factory")

◆ trybind()

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

Implements ACE_Allocator.

Definition at line 71 of file ZeroCopyAllocator_T.cpp.

72 {/* no-op */
73  ACE_ERROR((LM_ERROR,
74  ACE_TEXT("(%P|%t) %T not supported %a\n"))) ;
75  ACE_UNUSED_ARG(name);
76  ACE_UNUSED_ARG(pointer);
77  return -1;
78 }
#define ACE_ERROR(X)
const char *const name
Definition: debug.cpp:60
ACE_TEXT("TCP_Factory")

◆ unbind() [1/2]

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

Implements ACE_Allocator.

Definition at line 103 of file ZeroCopyAllocator_T.cpp.

104 {/* no-op */
105  ACE_ERROR((LM_ERROR,
106  ACE_TEXT("(%P|%t) %T not supported %a\n"))) ;
107  ACE_UNUSED_ARG(name);
108  return -1;
109 }
#define ACE_ERROR(X)
const char *const name
Definition: debug.cpp:60
ACE_TEXT("TCP_Factory")

◆ unbind() [2/2]

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

Implements ACE_Allocator.

Definition at line 113 of file ZeroCopyAllocator_T.cpp.

114 {/* no-op */
115  ACE_ERROR((LM_ERROR,
116  ACE_TEXT("(%P|%t) %T not supported %a\n"))) ;
117  ACE_UNUSED_ARG(name);
118  ACE_UNUSED_ARG(pointer);
119  return -1;
120 }
#define ACE_ERROR(X)
const char *const name
Definition: debug.cpp:60
ACE_TEXT("TCP_Factory")

Member Data Documentation

◆ firstTime_

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 63 of file ZeroCopyAllocator_T.h.

◆ pool_

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

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