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

Generated on 10 Aug 2018 for OpenDDS by  doxygen 1.6.1