Line data Source code
1 : /* 2 : * 3 : * 4 : * Distributed under the OpenDDS License. 5 : * See: http://www.opendds.org/license.html 6 : */ 7 : 8 : OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL 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 19 0 : FirstTimeFastAllocator<T, N>::FirstTimeFastAllocator() 20 0 : : firstTime_(true) 21 0 : , pool_() 22 : { 23 0 : } 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 * 30 0 : FirstTimeFastAllocator<T, N>::malloc(size_t nbytes) 31 : { 32 0 : if (firstTime_ && nbytes <= N * sizeof(T)) { 33 0 : firstTime_ = false; 34 0 : return (void*) pool_; 35 : 36 : } else { 37 : #if defined (ACE_HAS_ALLOC_HOOKS) 38 : return ACE_Allocator::instance()->malloc(nbytes); 39 : #else 40 0 : 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 47 0 : FirstTimeFastAllocator<T, N>::free(void *ptr) 48 : { 49 0 : if (ptr != (void*) pool_) { 50 : #if defined (ACE_HAS_ALLOC_HOOKS) 51 : ACE_Allocator::instance()->free(ptr); 52 : #else 53 0 : ACE_OS::free(ptr); 54 : #endif /* ACE_HAS_ALLOC_HOOKS */ 55 : } 56 0 : } 57 : 58 : } // namespace DCPS 59 : } // namespace OpenDDS 60 : 61 : OPENDDS_END_VERSIONED_NAMESPACE_DECL