sharelib/DefaultAllocator.h

Go to the documentation of this file.
00001 #ifndef DEFAULT_ALLOCATOR_H
00002 #define DEFAULT_ALLOCATOR_H
00003 
00012 #include "sharelib.h"
00013 
00019 #define BITS_ALIGNMENT 8
00020 
00021 namespace Share {
00029   template <
00030     unsigned char bitsAlignment,
00031     typename T >
00032   T genericAlignmenter (T input)
00033   {
00034     return
00035       (
00036        ((1 << bitsAlignment) - 1) |
00037        (input - 1)
00038       ) + 1;
00039   }
00040 
00047   template <typename T>
00048   inline T alignmenter (T input) {
00049     return genericAlignmenter <BITS_ALIGNMENT, T> (input);
00050   }
00051 
00057   class DefaultAllocator/*: public AbstractAllocator*/ {
00058     public:
00062       typedef RelocPtr<char> TRelocPtr;
00063 
00070       DefaultAllocator(void *atAddr, size_t segmentHeaderSize, size_t dataSize) throw (ShareException);
00071       ~DefaultAllocator();
00072 
00078       static size_t sizeNeeded (size_t segmentHeaderSize, size_t dataSize);
00079 
00086       void *alloc (size_t size) throw (ShareException);
00087 
00093       void free (void *addr) throw ();
00094 
00099       size_t size();
00100 
00104       size_t available();
00105 
00106     private:
00107       DefaultAllocator (const DefaultAllocator&);
00108       void operator= (const DefaultAllocator&);
00109 
00110     private:
00111       size_t size_;
00112       size_t available_;
00113       TRelocPtr current_;
00114   };
00115 }
00116 
00117 #endif // DEFAULT_ALLOCATOR_H

Generated on Sun Aug 26 17:42:59 2007 for ShareLibrary by  doxygen 1.5.2