2 * ***** BEGIN GPL LICENSE BLOCK *****
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * Contributor(s): Peter Schlaile <peter@schlaile.de> 2005
20 * ***** END GPL LICENSE BLOCK *****
23 /** \file memutil/MEM_Allocator.h
28 #ifndef __MEM_ALLOCATOR_H__
29 #define __MEM_ALLOCATOR_H__
32 #include "guardedalloc/MEM_guardedalloc.h"
33 #include "guardedalloc/MEM_sys_types.h"
35 template<typename _Tp>
38 typedef size_t size_type;
39 typedef ptrdiff_t difference_type;
41 typedef const _Tp* const_pointer;
42 typedef _Tp& reference;
43 typedef const _Tp& const_reference;
44 typedef _Tp value_type;
46 template<typename _Tp1>
48 typedef MEM_Allocator<_Tp1> other;
51 MEM_Allocator() throw() {}
52 MEM_Allocator(const MEM_Allocator&) throw() {}
54 template<typename _Tp1>
55 MEM_Allocator(const MEM_Allocator<_Tp1>) throw() { }
57 ~MEM_Allocator() throw() {}
59 pointer address(reference __x) const { return &__x; }
61 const_pointer address(const_reference __x) const { return &__x; }
63 // NB: __n is permitted to be 0. The C++ standard says nothing
64 // about what the return value is when __n == 0.
65 _Tp* allocate(size_type __n, const void* = 0) {
68 __ret = static_cast<_Tp*>(
69 MEM_mallocN(__n * sizeof(_Tp),
70 "STL MEM_Allocator"));
74 // __p is not permitted to be a null pointer.
75 void deallocate(pointer __p, size_type){
79 size_type max_size() const throw() {
80 return size_t(-1) / sizeof(_Tp);
83 void construct(pointer __p, const _Tp& __val) {
87 void destroy(pointer __p) {
92 #endif // __MEM_ALLOCATOR_H__