ZeroCopyAllocator_T.h

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 #ifndef ZEROCOPYALLOCATOR_H
00009 #define ZEROCOPYALLOCATOR_H
00010 
00011 #include /**/ "ace/pre.h"
00012 #include "ace/Malloc_Base.h"          /* Need ACE_Allocator */
00013 // not needed export for templates #include "dcps_export.h"
00014 
00015 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00016 # pragma once
00017 #endif /* ACE_LACKS_PRAGMA_ONCE */
00018 
00019 namespace OpenDDS {
00020 namespace DCPS {
00021 
00022 /// This allocator is "Fast" because it's pool can be on the stack
00023 ///   (If the object is on the stack and hence it does not require the
00024 ///    cost of allocating and deallocating on the heap.  It object is on the
00025 ///    heap then it requires just one allocation; not two.)
00026 /// @WARNING The object using this allocator must not have a scope smaller than this object !!!
00027 template <class T, std::size_t N>
00028 class FirstTimeFastAllocator : public ACE_Allocator {
00029 public:
00030   FirstTimeFastAllocator();
00031   virtual void *malloc(size_t nbytes);
00032   virtual void free(void *ptr);
00033 
00034   /// These methods are no-ops.
00035   virtual void *calloc(size_t nbytes, char initial_value = '\0');
00036   virtual void *calloc(size_t n_elem, size_t elem_size, char initial_value = '\0');
00037   virtual int remove();
00038   virtual int bind(const char *name, void *pointer, int duplicates = 0);
00039   virtual int trybind(const char *name, void *&pointer);
00040   virtual int find(const char *name, void *&pointer);
00041   virtual int find(const char *name);
00042   virtual int unbind(const char *name);
00043   virtual int unbind(const char *name, void *&pointer);
00044   virtual int sync(ssize_t len = -1, int flags = MS_SYNC);
00045   virtual int sync(void *addr, size_t len, int flags = MS_SYNC);
00046   virtual int protect(ssize_t len = -1, int prot = PROT_RDWR);
00047   virtual int protect(void *addr, size_t len, int prot = PROT_RDWR);
00048 #if defined (ACE_HAS_MALLOC_STATS)
00049   virtual void print_stats() const;
00050 #endif /* ACE_HAS_MALLOC_STATS */
00051   virtual void dump() const;
00052 
00053   T* pool() {
00054     return pool_;
00055   }
00056 
00057 private:
00058   /// is this the first time this is allocated?
00059   bool firstTime_;
00060 
00061   /// the pool of allocated memory.
00062   T pool_[N];
00063 };
00064 
00065 } // namespace  DDS
00066 } // namespace OpenDDS
00067 
00068 #if defined (__ACE_INLINE__)
00069 #include "dds/DCPS/ZeroCopyAllocator_T.inl"
00070 #endif /* __ACE_INLINE__ */
00071 
00072 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
00073 #include "dds/DCPS/ZeroCopyAllocator_T.cpp"
00074 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
00075 
00076 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
00077 #pragma implementation ("ZeroCopyAllocator_T.cpp")
00078 #endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */
00079 
00080 #include /**/ "ace/post.h"
00081 
00082 #endif /* ZEROCOPYALLOCATOR_H  */

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