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