|
Blender
V2.59
|
00001 /* 00002 * 00003 * ***** BEGIN GPL LICENSE BLOCK ***** 00004 * 00005 * This program is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU General Public License 00007 * as published by the Free Software Foundation; either version 2 00008 * of the License, or (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software Foundation, 00017 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00018 * 00019 * Contributor(s): Peter Schlaile <peter@schlaile.de> 2005 00020 * 00021 * ***** END GPL LICENSE BLOCK ***** 00022 */ 00023 00029 #ifndef MEM_ALLOCATOR_H 00030 #define MEM_ALLOCATOR_H 00031 00032 #include <stddef.h> 00033 #include "guardedalloc/MEM_guardedalloc.h" 00034 #include "guardedalloc/MEM_sys_types.h" 00035 00036 template<typename _Tp> 00037 struct MEM_Allocator 00038 { 00039 typedef size_t size_type; 00040 typedef ptrdiff_t difference_type; 00041 typedef _Tp* pointer; 00042 typedef const _Tp* const_pointer; 00043 typedef _Tp& reference; 00044 typedef const _Tp& const_reference; 00045 typedef _Tp value_type; 00046 00047 template<typename _Tp1> 00048 struct rebind { 00049 typedef MEM_Allocator<_Tp1> other; 00050 }; 00051 00052 MEM_Allocator() throw() {} 00053 MEM_Allocator(const MEM_Allocator&) throw() {} 00054 00055 template<typename _Tp1> 00056 MEM_Allocator(const MEM_Allocator<_Tp1>) throw() { } 00057 00058 ~MEM_Allocator() throw() {} 00059 00060 pointer address(reference __x) const { return &__x; } 00061 00062 const_pointer address(const_reference __x) const { return &__x; } 00063 00064 // NB: __n is permitted to be 0. The C++ standard says nothing 00065 // about what the return value is when __n == 0. 00066 _Tp* allocate(size_type __n, const void* = 0) { 00067 _Tp* __ret = 0; 00068 if (__n) 00069 __ret = static_cast<_Tp*>( 00070 MEM_mallocN(__n * sizeof(_Tp), 00071 "STL MEM_Allocator")); 00072 return __ret; 00073 } 00074 00075 // __p is not permitted to be a null pointer. 00076 void deallocate(pointer __p, size_type){ 00077 MEM_freeN(__p); 00078 } 00079 00080 size_type max_size() const throw() { 00081 return size_t(-1) / sizeof(_Tp); 00082 } 00083 00084 void construct(pointer __p, const _Tp& __val) { 00085 new(__p) _Tp(__val); 00086 } 00087 00088 void destroy(pointer __p) { 00089 __p->~_Tp(); 00090 } 00091 }; 00092 00093 #endif // MEM_ALLOCATOR_H