Blender V5.0
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
8
9#ifndef __MEM_ALLOCATOR_H__
10#define __MEM_ALLOCATOR_H__
11
13#include <cstddef>
14
15template<typename _Tp> struct MEM_Allocator {
16 using size_type = size_t;
17 using difference_type = ptrdiff_t;
18 using pointer = _Tp *;
19 using const_pointer = const _Tp *;
20 using reference = _Tp &;
21 using const_reference = const _Tp &;
22 using value_type = _Tp;
23
24 template<typename _Tp1> struct rebind {
26 };
27
28 MEM_Allocator() noexcept = default;
29 MEM_Allocator(const MEM_Allocator & /*other*/) noexcept = default;
30
31 template<typename _Tp1> MEM_Allocator(const MEM_Allocator<_Tp1> /*other*/) noexcept {}
32
33 ~MEM_Allocator() noexcept = default;
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 * /*unused*/ = nullptr)
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.
57 void deallocate(pointer __p, size_type /*unused*/)
58 {
59 MEM_freeN(static_cast<void *>(__p));
60 }
61
62 size_type max_size() const noexcept
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.
void * MEM_mallocN(size_t len, const char *str)
Definition mallocn.cc:128
void MEM_freeN(void *vmemh)
Definition mallocn.cc:113
MEM_Allocator< _Tp1 > other
const _Tp * const_pointer
ptrdiff_t difference_type
void destroy(pointer __p)
size_type max_size() const noexcept
void construct(pointer __p, const _Tp &__val)
~MEM_Allocator() noexcept=default
pointer address(reference __x) const
_Tp * allocate(size_type __n, const void *=nullptr)
MEM_Allocator() noexcept=default
const_pointer address(const_reference __x) const
const _Tp & const_reference
void deallocate(pointer __p, size_type)