メモリーリソースクラスは「アロケーターのベースクラス」と考えると良いでしょう。
つまりポリモーフィズムに対応したカスタムアロケーターを作る際に継承するクラスってことです。
ちなみに polymorphic_allocator は memory_resource オブジェクトを指すポインターを保持します。
memory_resource クラス (https://github.com/MacKomatsu/gcc/blob/master/libstdc%2B%2B-v3/include/experimental/memory_resource).
69 // Standard memory resources
70
71 // 8.5 Class memory_resource
72 class memory_resource
73 {
74 protected:
75 static constexpr size_t _S_max_align = alignof(max_align_t);
76
77 public:
78 virtual ~memory_resource() { }
79
80 void*
81 allocate(size_t __bytes, size_t __alignment = _S_max_align)
82 { return do_allocate(__bytes, __alignment); }
83
84 void
85 deallocate(void* __p, size_t __bytes, size_t __alignment = _S_max_align)
86 { return do_deallocate(__p, __bytes, __alignment); }
87
88 bool
89 is_equal(const memory_resource& __other) const noexcept
90 { return do_is_equal(__other); }
91
92 protected:
93 virtual void*
94 do_allocate(size_t __bytes, size_t __alignment) = 0;
95
96 virtual void
97 do_deallocate(void* __p, size_t __bytes, size_t __alignment) = 0;
98
99 virtual bool
100 do_is_equal(const memory_resource& __other) const noexcept = 0;
101 };
do_allocate() / do_deallocate() / do_is_equal() の 3 つの純粋仮想関数がありますね。
つまりこれら 3 つの関数のオーバーライドができるクラスってことです。
ベースクラスとして継承をしている例には __null_memory_resource クラスがあります。
__null_memory_resource クラス (https://github.com/MacKomatsu/gcc/blob/master/libstdc%2B%2B-v3/include/experimental/memory_resource).
344 template <typename _Alloc>
345 class __null_memory_resource : private memory_resource
346 {
347 protected:
348 void*
349 do_allocate(size_t, size_t)
350 { std::__throw_bad_alloc(); }
351
352 void
353 do_deallocate(void*, size_t, size_t) noexcept
354 { }
355
356 bool
357 do_is_equal(const memory_resource& __other) const noexcept
358 { return this == &__other; }
359
360 friend memory_resource* null_memory_resource() noexcept;
361 };
do_allocate() / do_deallocate() / do_is_equal() 関数をオーバーライドしていますよね。
Copyright 2018-2019, by Masaki Komatsu