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