ZeroCopyAllocator_T.inl

Go to the documentation of this file.
00001 /*
00002  *
00003  *
00004  * Distributed under the OpenDDS License.
00005  * See: http://www.opendds.org/license.html
00006  */
00007 
00008 OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
00009 
00010 namespace OpenDDS {
00011 namespace DCPS {
00012 
00013 template<class T, std::size_t N> ACE_INLINE
00014 FirstTimeFastAllocator<T, N>::FirstTimeFastAllocator()
00015   : firstTime_(true)
00016   , pool_()
00017 {
00018 }
00019 
00020 template<class T, std::size_t N> ACE_INLINE
00021 void *
00022 FirstTimeFastAllocator<T, N>::malloc(size_t nbytes)
00023 {
00024   if (firstTime_ && nbytes <= N * sizeof(T)) {
00025     firstTime_ = false;
00026     return (void*) pool_;
00027 
00028   } else {
00029 #if defined (ACE_HAS_ALLOC_HOOKS)
00030     return ACE_Allocator::instance()->malloc(nbytes);
00031 #else
00032     return ACE_OS::malloc(nbytes);
00033 #endif /* ACE_HAS_ALLOC_HOOKS */
00034   }
00035 }
00036 
00037 template<class T, std::size_t N> ACE_INLINE
00038 void
00039 FirstTimeFastAllocator<T, N>::free(void *ptr)
00040 {
00041   if (ptr != (void*) pool_) {
00042 #if defined (ACE_HAS_ALLOC_HOOKS)
00043      ACE_Allocator::instance()->free(ptr);
00044 #else
00045     ACE_OS::free(ptr);
00046 #endif /* ACE_HAS_ALLOC_HOOKS */
00047   }
00048 }
00049 
00050 } // namespace  DDS
00051 } // namespace OpenDDS
00052 
00053 OPENDDS_END_VERSIONED_NAMESPACE_DECL
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 10 Aug 2018 for OpenDDS by  doxygen 1.6.1