Allocator.hxx
1 // Copyright (C) 2001-2009 Vivien Mallet, Marc Fragu
2 //
3 // This file is part of the linear-algebra library Seldon,
4 // http://seldon.sourceforge.net/.
5 //
6 // Seldon is free software; you can redistribute it and/or modify it under the
7 // terms of the GNU Lesser General Public License as published by the Free
8 // Software Foundation; either version 2.1 of the License, or (at your option)
9 // any later version.
10 //
11 // Seldon is distributed in the hope that it will be useful, but WITHOUT ANY
12 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
14 // more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public License
17 // along with Seldon. If not, see http://www.gnu.org/licenses/.
18 
19 
20 #ifndef SELDON_FILE_ALLOCATOR_HXX
21 
22 namespace Seldon
23 {
24 
25 
27  // MALLOCALLOC //
29 
30 
31  template <class T>
33  {
34  public:
35  typedef T value_type;
36  typedef T* pointer;
37  typedef const T* const_pointer;
38  typedef T& reference;
39  typedef const T& const_reference;
40 
43  static const bool KeepDataReallocate = true;
44 
45  public:
46 
47  static pointer allocate(size_t num, void* h = 0);
48  static void deallocate(pointer data, size_t num, void* h = 0);
49  static void* reallocate(pointer data, size_t num, void* h = 0);
50  static void memoryset(pointer data, char c, size_t num);
51  static void memorycpy(pointer datat, pointer datas, size_t num);
52 
53  };
54 
55 
57  // CALLOCALLOC //
59 
60 
61  template <class T>
63  {
64  public:
65  typedef T value_type;
66  typedef T* pointer;
67  typedef const T* const_pointer;
68  typedef T& reference;
69  typedef const T& const_reference;
70 
73  static const bool KeepDataReallocate = true;
74 
75  public:
76 
77  static pointer allocate(size_t num, void* h = 0);
78  static void deallocate(pointer data, size_t num, void* h = 0);
79  static void* reallocate(pointer data, size_t num, void* h = 0);
80  static void memoryset(pointer data, char c, size_t num);
81  static void memorycpy(pointer datat, pointer datas, size_t num);
82  };
83 
84 
86  // NEWALLOC //
88 
89 
90  template <class T>
91  class NewAlloc
92  {
93  public:
94  typedef T value_type;
95  typedef T* pointer;
96  typedef const T* const_pointer;
97  typedef T& reference;
98  typedef const T& const_reference;
99 
102  static const bool KeepDataReallocate = false;
103 
104  public:
105 
106  static pointer allocate(size_t num, void* h = 0);
107  static void deallocate(pointer data, size_t num, void* h = 0);
108  static void* reallocate(pointer data, size_t num, void* h = 0);
109  static void memoryset(pointer data, char c, size_t num);
110  static void memorycpy(pointer datat, pointer datas, size_t num);
111  };
112 
113 
115  // MallocObject //
117 
118 
119  template <class T>
121  {
122  public:
123  typedef T value_type;
124  typedef T* pointer;
125  typedef const T* const_pointer;
126  typedef T& reference;
127  typedef const T& const_reference;
128 
131  static const bool KeepDataReallocate = false;
132 
133  public:
134 
135  static pointer allocate(size_t num, void* h = 0);
136  static void deallocate(pointer data, size_t num, void* h = 0);
137  static void* reallocate(pointer data, size_t num, void* h = 0);
138  static void memoryset(pointer data, char c, size_t num);
139  static void memorycpy(pointer datat, pointer datas, size_t num);
140  };
141 
142 
144  // NANALLOC //
146 
147 
148  template <class T>
149  class NaNAlloc
150  {
151  public:
152  typedef T value_type;
153  typedef T* pointer;
154  typedef const T* const_pointer;
155  typedef T& reference;
156  typedef const T& const_reference;
157 
160  static const bool KeepDataReallocate = true;
161 
162  public:
163 
164  static pointer allocate(size_t num, void* h = 0);
165  static void deallocate(pointer data, size_t num, void* h = 0);
166  static void* reallocate(pointer data, size_t num, void* h = 0);
167  static void memoryset(pointer data, char c, size_t num);
168  static void memorycpy(pointer datat, pointer datas, size_t num);
169  };
170 
171 
173  template<class Storage, class T>
175  {
176  public :
177  // default choice : SELDON_DEFAULT_ALLOCATOR
178  typedef SELDON_DEFAULT_ALLOCATOR<T> allocator;
179 
180  };
181 
182 } // namespace Seldon.
183 
184 #define SELDON_FILE_ALLOCATOR_HXX
185 #endif
Seldon::SeldonDefaultAllocator
Selection of default allocator depending on storage and value type.
Definition: Allocator.hxx:174
Seldon::MallocAlloc
Definition: Allocator.hxx:32
Seldon::NaNAlloc::KeepDataReallocate
static const bool KeepDataReallocate
true if the allocator keeps previous elements when calling reallocate
Definition: Allocator.hxx:160
Seldon::CallocAlloc
Definition: Allocator.hxx:62
Seldon::NewAlloc
Definition: Allocator.hxx:91
Seldon::MallocObject::KeepDataReallocate
static const bool KeepDataReallocate
true if the allocator keeps previous elements when calling reallocate
Definition: Allocator.hxx:131
Seldon::MallocObject
Definition: Allocator.hxx:120
Seldon::MallocAlloc::KeepDataReallocate
static const bool KeepDataReallocate
true if the allocator keeps previous elements when calling reallocate
Definition: Allocator.hxx:43
Seldon::CallocAlloc::KeepDataReallocate
static const bool KeepDataReallocate
true if the allocator keeps previous elements when calling reallocate
Definition: Allocator.hxx:73
Seldon::NaNAlloc
Definition: Allocator.hxx:149
Seldon::NewAlloc::KeepDataReallocate
static const bool KeepDataReallocate
true if the allocator keeps previous elements when calling reallocate
Definition: Allocator.hxx:102
Seldon
Seldon namespace.
Definition: Array.cxx:24