00001
00002
00003
00004
00005
00006
00007
00008 #ifndef ZEROCOPYALLOCATOR_H
00009 #define ZEROCOPYALLOCATOR_H
00010
00011 #include "ace/pre.h"
00012 #include "ace/Malloc_Base.h"
00013
00014
00015 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00016 # pragma once
00017 #endif
00018
00019 namespace OpenDDS {
00020 namespace DCPS {
00021
00022
00023
00024
00025
00026
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
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
00051 virtual void dump() const;
00052
00053 T* pool() {
00054 return pool_;
00055 }
00056
00057 private:
00058
00059 bool firstTime_;
00060
00061
00062 T pool_[N];
00063 };
00064
00065 }
00066 }
00067
00068 #if defined (__ACE_INLINE__)
00069 #include "dds/DCPS/ZeroCopyAllocator_T.inl"
00070 #endif
00071
00072 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
00073 #include "dds/DCPS/ZeroCopyAllocator_T.cpp"
00074 #endif
00075
00076 #if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
00077 #pragma implementation ("ZeroCopyAllocator_T.cpp")
00078 #endif
00079
00080 #include "ace/post.h"
00081
00082 #endif