|
Sierra Toolkit
Version of the Day
|
00001 #ifndef RDESTL_ALLOCATOR_H 00002 #define RDESTL_ALLOCATOR_H 00003 00004 namespace rde 00005 { 00006 00007 // CONCEPT! 00008 class allocator 00009 { 00010 public: 00011 explicit allocator(const char* name = "DEFAULT"): m_name(name) {} 00012 // Copy ctor generated by compiler. 00013 // allocator(const allocator&) 00014 ~allocator() {} 00015 00016 // Generated by compiler. 00017 //allocator& operator=(const allocator&) 00018 00019 void* allocate(unsigned int bytes, int flags = 0); 00020 // Not supported for standard allocator for the time being. 00021 void* allocate_aligned(unsigned int bytes, unsigned int alignment, int flags = 0); 00022 void deallocate(void* ptr, unsigned int bytes); 00023 00024 const char* get_name() const; 00025 00026 private: 00027 const char* m_name; 00028 }; 00029 00030 // True if lhs can free memory allocated by rhs and vice-versa. 00031 inline bool operator==(const allocator& /*lhs*/, const allocator& /*rhs*/) 00032 { 00033 return true; 00034 } 00035 inline bool operator!=(const allocator& lhs, const allocator& rhs) 00036 { 00037 return !(lhs == rhs); 00038 } 00039 00040 inline void* allocator::allocate(unsigned int bytes, int) 00041 { 00042 return operator new(bytes); 00043 } 00044 00045 inline void allocator::deallocate(void* ptr, unsigned int) 00046 { 00047 operator delete(ptr); 00048 } 00049 00050 } // namespace rde 00051 00052 //----------------------------------------------------------------------------- 00053 #endif // #ifndef RDESTL_ALLOCATOR_H