OpenDDS  Snapshot(2023/04/28-20:55)
ZeroCopyAllocator_T.inl
Go to the documentation of this file.
1 /*
2  *
3  *
4  * Distributed under the OpenDDS License.
5  * See: http://www.opendds.org/license.html
6  */
7 
9 
10 namespace OpenDDS {
11 namespace DCPS {
12 
13 #if defined (_MSC_VER) && (_MSC_VER >= 1400)
14 # pragma warning (push)
15 # pragma warning (disable:4351)
16 #endif
17 
18 template<class T, std::size_t N> ACE_INLINE
20  : firstTime_(true)
21  , pool_()
22 {
23 }
24 #if defined (_MSC_VER) && (_MSC_VER >= 1400)
25 # pragma warning (pop)
26 #endif
27 
28 template<class T, std::size_t N> ACE_INLINE
29 void *
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 }
44 
45 template<class T, std::size_t N> ACE_INLINE
46 void
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 }
57 
58 } // namespace DCPS
59 } // namespace OpenDDS
60 
void free(void *)
virtual void free(void *ptr)=0
void * malloc(size_t)
static ACE_Allocator * instance(void)
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
#define ACE_INLINE
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28
virtual void * malloc(size_type nbytes)=0