Blender  V2.93
MEM_Allocator.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
21 #ifndef __MEM_ALLOCATOR_H__
22 #define __MEM_ALLOCATOR_H__
23 
25 #include <stddef.h>
26 
27 template<typename _Tp> struct MEM_Allocator {
28  typedef size_t size_type;
29  typedef ptrdiff_t difference_type;
30  typedef _Tp *pointer;
31  typedef const _Tp *const_pointer;
32  typedef _Tp &reference;
33  typedef const _Tp &const_reference;
34  typedef _Tp value_type;
35 
36  template<typename _Tp1> struct rebind {
38  };
39 
40  MEM_Allocator() throw()
41  {
42  }
43  MEM_Allocator(const MEM_Allocator &) throw()
44  {
45  }
46 
47  template<typename _Tp1> MEM_Allocator(const MEM_Allocator<_Tp1>) throw()
48  {
49  }
50 
51  ~MEM_Allocator() throw()
52  {
53  }
54 
56  {
57  return &__x;
58  }
59 
61  {
62  return &__x;
63  }
64 
65  // NB: __n is permitted to be 0. The C++ standard says nothing
66  // about what the return value is when __n == 0.
67  _Tp *allocate(size_type __n, const void * = 0)
68  {
69  _Tp *__ret = NULL;
70  if (__n)
71  __ret = static_cast<_Tp *>(MEM_mallocN(__n * sizeof(_Tp), "STL MEM_Allocator"));
72  return __ret;
73  }
74 
75  // __p is not permitted to be a null pointer.
77  {
78  MEM_freeN(__p);
79  }
80 
81  size_type max_size() const throw()
82  {
83  return size_t(-1) / sizeof(_Tp);
84  }
85 
86  void construct(pointer __p, const _Tp &__val)
87  {
88  new (__p) _Tp(__val);
89  }
90 
91  void destroy(pointer __p)
92  {
93  __p->~_Tp();
94  }
95 };
96 
97 #endif // __MEM_ALLOCATOR_H__
Read Guarded memory(de)allocation.
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:41
void *(* MEM_mallocN)(size_t len, const char *str)
Definition: mallocn.c:47
MEM_Allocator< _Tp1 > other
Definition: MEM_Allocator.h:37
void destroy(pointer __p)
Definition: MEM_Allocator.h:91
void construct(pointer __p, const _Tp &__val)
Definition: MEM_Allocator.h:86
const _Tp & const_reference
Definition: MEM_Allocator.h:33
size_t size_type
Definition: MEM_Allocator.h:28
_Tp * allocate(size_type __n, const void *=0)
Definition: MEM_Allocator.h:67
MEM_Allocator(const MEM_Allocator< _Tp1 >)
Definition: MEM_Allocator.h:47
const _Tp * const_pointer
Definition: MEM_Allocator.h:31
pointer address(reference __x) const
Definition: MEM_Allocator.h:55
MEM_Allocator(const MEM_Allocator &)
Definition: MEM_Allocator.h:43
ptrdiff_t difference_type
Definition: MEM_Allocator.h:29
size_type max_size() const
Definition: MEM_Allocator.h:81
const_pointer address(const_reference __x) const
Definition: MEM_Allocator.h:60
void deallocate(pointer __p, size_type)
Definition: MEM_Allocator.h:76