lean cpp library
A lean C++ library providing efficient utility classes for high-performance C++ applications.
aligned.h
00001 /*****************************************************/
00002 /* lean Memory                  (c) Tobias Zirr 2011 */
00003 /*****************************************************/
00004 
00005 #ifndef LEAN_MEMORY_ALIGNED
00006 #define LEAN_MEMORY_ALIGNED
00007 
00008 #include "../lean.h"
00009 #include "alignment.h"
00010 #include "default_heap.h"
00011 
00012 namespace lean
00013 {
00014 namespace memory
00015 {
00017 
00020     template <size_t Alignment, class Heap = default_heap>
00021     class aligned : public stack_aligned<Alignment>
00022     {
00023     private:
00024 #ifndef LEAN0X_NO_DELETE_METHODS
00025 
00026         LEAN_INLINE void* operator new[](size_t size) = delete;
00028         LEAN_INLINE void operator delete[](void *memory) = delete;
00029 #else
00030 
00031         LEAN_INLINE void* operator new[](size_t size);
00033         LEAN_INLINE void operator delete[](void *memory);
00034 #endif
00035 
00036     protected:
00037         LEAN_INLINE aligned() { };
00038 #ifndef LEAN_OPTIMIZE_DEFAULT_DESTRUCTOR
00039         LEAN_INLINE ~aligned() throw() { };
00040 #endif
00041 
00042     public:
00044         LEAN_INLINE void* operator new(size_t size)
00045         {
00046             return Heap::allocate<Alignment>(size);
00047         }
00049         LEAN_INLINE void operator delete(void *memory)
00050         {
00051             Heap::free<Alignment>(memory);
00052         }
00053     };
00054 
00055 } // namespace
00056 
00057 using memory::aligned;
00058 
00059 } // namespace
00060 
00061 #endif