Blender  V3.3
MEM_Allocator.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #ifndef __MEM_ALLOCATOR_H__
8 #define __MEM_ALLOCATOR_H__
9 
11 #include <stddef.h>
12 
13 template<typename _Tp> struct MEM_Allocator {
14  typedef size_t size_type;
15  typedef ptrdiff_t difference_type;
16  typedef _Tp *pointer;
17  typedef const _Tp *const_pointer;
18  typedef _Tp &reference;
19  typedef const _Tp &const_reference;
20  typedef _Tp value_type;
21 
22  template<typename _Tp1> struct rebind {
24  };
25 
26  MEM_Allocator() throw()
27  {
28  }
29  MEM_Allocator(const MEM_Allocator &) throw()
30  {
31  }
32 
33  template<typename _Tp1> MEM_Allocator(const MEM_Allocator<_Tp1>) throw()
34  {
35  }
36 
37  ~MEM_Allocator() throw()
38  {
39  }
40 
42  {
43  return &__x;
44  }
45 
47  {
48  return &__x;
49  }
50 
51  /* NOTE: `__n` is permitted to be 0.
52  * The C++ standard says nothing about what the return value is when `__n == 0`. */
53  _Tp *allocate(size_type __n, const void * = 0)
54  {
55  _Tp *__ret = NULL;
56  if (__n)
57  __ret = static_cast<_Tp *>(MEM_mallocN(__n * sizeof(_Tp), "STL MEM_Allocator"));
58  return __ret;
59  }
60 
61  // __p is not permitted to be a null pointer.
63  {
64  MEM_freeN(__p);
65  }
66 
67  size_type max_size() const throw()
68  {
69  return size_t(-1) / sizeof(_Tp);
70  }
71 
72  void construct(pointer __p, const _Tp &__val)
73  {
74  new (__p) _Tp(__val);
75  }
76 
77  void destroy(pointer __p)
78  {
79  __p->~_Tp();
80  }
81 };
82 
83 #endif // __MEM_ALLOCATOR_H__
Read Guarded memory(de)allocation.
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:27
void *(* MEM_mallocN)(size_t len, const char *str)
Definition: mallocn.c:33
MEM_Allocator< _Tp1 > other
Definition: MEM_Allocator.h:23
void destroy(pointer __p)
Definition: MEM_Allocator.h:77
void construct(pointer __p, const _Tp &__val)
Definition: MEM_Allocator.h:72
const _Tp & const_reference
Definition: MEM_Allocator.h:19
size_t size_type
Definition: MEM_Allocator.h:14
_Tp * allocate(size_type __n, const void *=0)
Definition: MEM_Allocator.h:53
MEM_Allocator(const MEM_Allocator< _Tp1 >)
Definition: MEM_Allocator.h:33
const _Tp * const_pointer
Definition: MEM_Allocator.h:17
pointer address(reference __x) const
Definition: MEM_Allocator.h:41
MEM_Allocator(const MEM_Allocator &)
Definition: MEM_Allocator.h:29
ptrdiff_t difference_type
Definition: MEM_Allocator.h:15
size_type max_size() const
Definition: MEM_Allocator.h:67
const_pointer address(const_reference __x) const
Definition: MEM_Allocator.h:46
void deallocate(pointer __p, size_type)
Definition: MEM_Allocator.h:62