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 namespace OpenDDS {
00009 namespace DCPS {
00010 
00011 template<class T, std::size_t N> ACE_INLINE
00012 FirstTimeFastAllocator<T, N>::FirstTimeFastAllocator()
00013   : firstTime_(true)
00014 {
00015 }
00016 
00017 template<class T, std::size_t N> ACE_INLINE
00018 void *
00019 FirstTimeFastAllocator<T, N>::malloc(size_t nbytes)
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 }
00033 
00034 template<class T, std::size_t N> ACE_INLINE
00035 void
00036 FirstTimeFastAllocator<T, N>::free(void *ptr)
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 }
00046 
00047 } // namespace  DDS
00048 } // namespace OpenDDS

Generated on Fri Feb 12 20:05:29 2016 for OpenDDS by  doxygen 1.4.7