src/zserio/pmr/NewDeleteResource.h
Line | Count | Source |
1 | | #ifndef ZSERIO_PMR_NEW_DELETE_RESOURCE_H_INC |
2 | | #define ZSERIO_PMR_NEW_DELETE_RESOURCE_H_INC |
3 | | |
4 | | #include <new> |
5 | | |
6 | | #include "zserio/Types.h" |
7 | | #include "zserio/pmr/MemoryResource.h" |
8 | | |
9 | | namespace zserio |
10 | | { |
11 | | namespace pmr |
12 | | { |
13 | | namespace detail |
14 | | { |
15 | | |
16 | | /** |
17 | | * Default memory resource which will be used by polymorphic allocators defined by zserio. |
18 | | */ |
19 | | class NewDeleteResource : public MemoryResource |
20 | | { |
21 | | private: |
22 | | void* doAllocate(size_t bytes, size_t) override |
23 | 189 | { |
24 | 189 | return ::operator new(bytes); |
25 | 189 | } |
26 | | |
27 | | void doDeallocate(void* storage, size_t, size_t) override |
28 | 189 | { |
29 | 189 | ::operator delete(storage); |
30 | 189 | } |
31 | | |
32 | | bool doIsEqual(const MemoryResource& other) const noexcept override |
33 | 2 | { |
34 | 2 | return this == &other; |
35 | 2 | } |
36 | | }; |
37 | | |
38 | | } // namespace detail |
39 | | |
40 | | /** |
41 | | * Gets pointer to (default) new delete resource. |
42 | | */ |
43 | | MemoryResource* getNewDeleteResource() noexcept; |
44 | | |
45 | | } // namespace pmr |
46 | | } // namespace zserio |
47 | | |
48 | | #endif // ZSERIO_PMR_NEW_DELETE_RESOURCE_H_INC |