YSTest: memory_resource.h 源文件

YSTest PreAlpha_b900_20201012 The YSLib Test Project

memory_resource.h
浏览该文件的文档.
1 /*
2 © 2018-2020 FrankHB.
3
4 This file is part of the YSLib project, and may only be used,
5 modified, and distributed under the terms of the YSLib project
6 license, LICENSE.TXT. By continuing to use, modify, or distribute
7 this file you indicate that you have read the license and
8 understand and accept it fully.
9 */
10
54 #ifndef YB_INC_ystdex_memory_resource_h_
55 #define YB_INC_ystdex_memory_resource_h_ 1
56
57 #include "memory.hpp" // for internal "memory.hpp", byte, size_t, yalignof,
58 // yconstraint, yaligned, SIZE_MAX, std::length_error, yforward,
59 // ystdex::uninitialized_construct_using_allocator, std::pair, yassume, list,
60 // equal_to, std::hash;
61 // NOTE: See "placement.hpp" for comments on inclusion conditions.
62 #if (YB_IMPL_MSCPP >= 1910 && _MSVC_LANG >= 201603) \
63 || (__cplusplus >= 201603L && __has_include(<memory_resource>))
64 # include <memory_resource>
65 # if (YB_IMPL_MSCPP >= 1910 && _MSVC_LANG >= 201603) \
66 || __cpp_lib_memory_resource >= 201603L
67 # define YB_Has_memory_resource 1
68 # endif
69 #elif __cplusplus > 201402L && __has_include(<experimental/memory_resource>)
70 // NOTE: For exposition only. The implementations in libstdc++ and libc++ are
71 // incomplete as of ISO C++17 is published.
72 # include <experimental/memory_resource>
73 # if __cpp_lib_experimental_memory_resources >= 201402L
74 # define YB_Has_memory_resource 2
75 # endif
76 #endif
77 #if YB_Has_memory_resource && __cplusplus > 201703L \
78 && (!defined(__GLIBCXX__) || __GLIBCXX__ > 20190731)
79 // XXX: See https://github.com/cplusplus/draft/issues/3111.
80 // XXX: See https://gcc.gnu.org/viewcvs/gcc/trunk/libstdc++-v3/include/std/memory?r1=273515&r2=273945.
81 # define YB_Impl_P0339R6 true
82 #else
83 # define YB_Impl_P0339R6 false
84 #endif
85 #if YB_Has_memory_resource != 1
86 # include <tuple> // for std::tuple, std::forward_as_tuple, std::tuple_cat;
87 # include "operators.hpp" // for equality_comparable;
88 #endif
89 #include "base.h" // for noncopyable, nonmovable;
90 #include "cstdint.hpp" // for is_power_of_2_positive;
91 #include "list.hpp"// for list;
92 #include <vector> // for std::vector;
93 #include <unordered_map> // for std::unordered_map;
94 #include "algorithm.hpp" // for ystdex::max;
95 #if YB_Has_memory_resource != 1
96 # if (defined(__GLIBCXX__) && !(defined(_GLIBCXX_USE_C99_STDINT_TR1) \
97 && defined(_GLIBCXX_HAS_GTHREADS))) \
98 || (defined(_LIBCPP_VERSION) && defined(_LIBCPP_HAS_NO_THREADS))
99 // XXX: The synchonization does not work. However, this still makes
100 // %synchronized_pool_resource different than %unsynchronized_pool_resource in
101 // %ystdex::pmr. Preserving %ystdex::single_thread pseudo implementation
102 // introduces some basic checks of sanity on mutex types.
103 # include "pseudo_mutex.h" // for ystdex::single_thread::mutex,
104 // ystdex::single_thread::lock_guard;
105 # define YB_Impl_mutex_ns ystdex::single_thread
106 # else
107 # include <mutex> // for std::mutex, std::lock_guard;
108 # define YB_Impl_mutex_ns std
109 # endif
110 # include "type_pun.hpp" // for pun_ref;
111 #endif
112
120 #ifndef __cpp_lib_memory_resource
121 # if (YB_IMPL_MSCPP >= 1910 && _MSVC_LANG >= 201603) || __cplusplus >= 201603L
122 # define __cpp_lib_memory_resource 201603L
123 # endif
124 #endif
125
126
128 namespace ystdex
129 {
130
131 // TODO: Check support of P0591R4 and use %std::pmr::polymorphic_allocator if
132 // possible.
133
134 namespace details
135 {
136
138
139 template<size_t _vSize>
140 YB_ATTR_nodiscard YB_PURE inline size_t
141 get_size_of_n(size_t n)
142 {
143 size_t res(n * _vSize);
144
145 return size_t(static_cast<size_t>(-1) / _vSize) < n ? size_t(-1) : res;
146 }
147 template<>
148 YB_ATTR_nodiscard YB_PURE inline size_t
149 get_size_of_n<1>(size_t n)
150 {
151 return n;
152 }
154
155 } // namespace details;
156
157 namespace pmr
158 {
159
160 inline namespace cpp2017
161 {
162
163 // NOTE: Microsoft VC++ 15.8.2 implements ISO C++17 version (using WG21 N4700
164 // suggested by the assertion messages), while current libstdc++ and libc++
165 // only provide %std::experimental::fundamentals_v2 version, although some
166 // resoultions have applied on libc++.
167 #if YB_Has_memory_resource == 1
168 using std::pmr::memory_resource;
169
170 using std::pmr::get_default_resource;
171 #else
172
174
178 class YB_API YB_ATTR_novtable memory_resource
179 : private equality_comparable<memory_resource>
180 {
181 private:
182 static constexpr size_t max_align = yalignof(std::max_align_t);
183
184 public:
190 memory_resource() = default;
191 memory_resource(const memory_resource&) = default;
193 // XXX: Microsoft VC++, libstdc++ and libc++ all defined the destructor
194 // inline. Keeping it out-of-line for style consistency and to avoid
195 // Clang++ warning [-Wweak-vtables] reilably.
197 virtual
198 ~memory_resource();
199
200 YB_ATTR_nodiscard friend bool
201 operator==(const memory_resource& a, const memory_resource& b) ynothrow
202 {
203 return &a == &b || a.is_equal(b);
204 }
205
210 YB_ALLOCATOR YB_ATTR_returns_nonnull void*
211 allocate(size_t bytes, size_t alignment = max_align)
212 {
213 // NOTE: This is not specified directly by the specification, but the
214 // resolution of LWG 2843 has made the requirement on the alignment
215 // same to %do_allocation. Microsoft VC++ 15.8.2 implements it using
216 // an assertion here similarly. Libc++ experimental does not assert and
217 // does silently round up the alignment value which is always the
218 // maximul alignment in its %__resource_adaptor_imp::do_allocate.
219 yconstraint(is_power_of_2_positive(alignment));
220
221 const auto p(do_allocate(bytes, alignment));
222
223 return yaligned(p, alignment);
224 }
225
226 void
227 deallocate(void* p, size_t bytes, size_t alignment = max_align)
228 {
229 // NOTE: The alignment requirement is same to %allocate.
230 yconstraint(is_power_of_2_positive(alignment));
231 return do_deallocate(p, bytes, alignment);
232 }
233
234 YB_ATTR_nodiscard bool
235 is_equal(const memory_resource& other) const ynothrow
236 {
237 // NOTE: See LWG 2843.
238 return do_is_equal(other);
239 }
240
241 // XXX: LWG 2724 is implemented by Microsoft VC++ 15.8.2. Not sure which is
242 // the initial version as it seems undocumented.
243 // XXX: LWG 2724 is NOT implemented in libstdc++ and libc++ in
244 // %std::experimental currently. It is not likely to be because the issue
245 // is resolved after adoption of P0220R1.
246 private:
248 YB_ALLOCATOR YB_ATTR_returns_nonnull virtual void*
249 do_allocate(size_t, size_t) = 0;
250
251 virtual void
252 do_deallocate(void*, size_t, size_t) = 0;
253
254 YB_ATTR_nodiscard virtual bool
255 do_is_equal(const memory_resource&) const ynothrow = 0;
256 };
257
258
259 YB_ATTR_nodiscard YB_API YB_ATTR_returns_nonnull memory_resource*
260 get_default_resource() ynothrow;
262 #endif
263
264 } // inline namespace cpp2017;
265
266
267 #if YB_Impl_P0339R6
268 using std::pmr::polymorphic_allocator;
269 #else
270
274 template<class _type = byte>
275 class polymorphic_allocator
276 {
277 public:
278 using value_type = _type;
279
280 private:
282 memory_resource* memory_rsrc;
283
284 public:
285 polymorphic_allocator() ynothrow
286 : memory_rsrc(get_default_resource())
287 {}
288
290 YB_NONNULL(2)
291 polymorphic_allocator(memory_resource* r)
292 : memory_rsrc(r)
293 {
294 yconstraint(r);
295 }
296 polymorphic_allocator(const polymorphic_allocator& other) = default;
297 template<typename _tOther>
298 polymorphic_allocator(const polymorphic_allocator<_tOther>& other) ynothrow
299 : memory_rsrc(other.resource())
300 {}
301
303 polymorphic_allocator&
304 operator=(const polymorphic_allocator&) = delete;
305
307 YB_ALLOCATOR YB_ATTR_returns_nonnull _type*
308 allocate(size_t n)
309 {
310 return static_cast<_type*>(memory_rsrc->allocate(
311 details::get_size_of_n<sizeof(_type)>(n), yalignof(_type)));
312 }
313
314 void
315 deallocate(_type* p, size_t n)
316 {
317 memory_rsrc->deallocate(p, details::get_size_of_n<sizeof(_type)>(n),
318 yalignof(_type));
319 }
320
326 void*
327 allocate_bytes(size_t nbytes, size_t alignment = yalignof(std::max_align_t))
328 {
329 return memory_rsrc->allocate(nbytes, alignment);
330 }
331
332 void
333 deallocate_bytes(void* p, size_t nbytes, size_t alignment = yalignof(std::max_align_t))
334 {
335 return memory_rsrc->deallocate(p, nbytes, alignment);
336 }
337
338 template<typename _tObj>
339 _tObj*
340 allocate_object(size_t n = 1)
341 {
342 if(SIZE_MAX / sizeof(_tObj) >= n)
343 return static_cast<_tObj*>(allocate_bytes(n * sizeof(_tObj),
344 yalignof(_tObj)));
345 throw std::length_error("polymorphic_allocator::allocate_object");
346 }
347
348 template<typename _tObj>
349 void
350 deallocate_object(_tObj* p, size_t n = 1)
351 {
352 deallocate_bytes(p, n * sizeof(_tObj), yalignof(_tObj));
353 }
354
355 template<typename _tObj, typename... _tCtorParams>
356 _tObj*
357 new_object(_tCtorParams&&... ctor_args)
358 {
359 _tObj* p(allocate_object<_tObj>());
360
361 try
362 {
363 construct(p, yforward(ctor_args)...);
364 }
365 catch(...)
366 {
367 deallocate_object(p);
368 throw;
369 }
370 return p;
371 }
372
373 template<typename _tObj>
374 void delete_object(_tObj* p)
375 {
376 destroy(p);
377 deallocate_object(p);
378 }
380
385 template<typename _tObj, typename... _tParams>
386 YB_NONNULL(2) void
387 construct(_tObj* p, _tParams&&... args)
388 {
389 ystdex::uninitialized_construct_using_allocator(p, *this,
390 yforward(args)...);
391 }
392
393 YB_ATTR_nodiscard polymorphic_allocator
394 select_on_container_copy_construction() const
395 {
396 return {};
397 }
398
399 YB_ATTR_nodiscard YB_ATTR_returns_nonnull memory_resource*
400 resource() const
401 {
402 return memory_rsrc;
403 }
404 };
405
406 template<typename _type1, typename _type2>
407 YB_ATTR_nodiscard inline bool
408 operator==(const polymorphic_allocator<_type1>& a,
409 const polymorphic_allocator<_type2>& b) ynothrow
410 {
411 return *a.resource() == *b.resource();
412 }
413
414 template<typename _type1, typename _type2>
415 YB_ATTR_nodiscard inline bool
416 operator!=(const polymorphic_allocator<_type1>& a,
417 const polymorphic_allocator<_type2>& b) ynothrow
418 {
419 return !(a == b);
420 }
421 #endif
422
423
424 inline namespace cpp2017
425 {
426
427 #if YB_Has_memory_resource == 1
428 using std::pmr::new_delete_resource;
429 using std::pmr::null_memory_resource;
430 using std::pmr::set_default_resource;
431
432 using std::pmr::pool_options;
433 #else
434
436 YB_ATTR_nodiscard YB_API memory_resource*
437 new_delete_resource() ynothrow;
438
439 YB_ATTR_nodiscard YB_API memory_resource*
440 null_memory_resource() ynothrow;
441
443 YB_API YB_ATTR_returns_nonnull memory_resource*
444 set_default_resource(memory_resource*) ynothrow;
445
446
451 struct YB_API pool_options
452 {
453 size_t max_blocks_per_chunk = 0;
454 size_t largest_required_pool_block = 0;
455 };
457 #endif
458
459 } // inline namespace cpp2017;
460
462
463
465
471 YB_API void
472 adjust_pool_options(pool_options&);
473
474
479 class YB_API resource_pool : private noncopyable
480 {
481 private:
483 class chunk_t;
485 using id_t = size_t;
487 using chunk_pr_t = std::pair<id_t, chunk_t>;
489
490 using chunks_t = list<chunk_pr_t, polymorphic_allocator<chunk_pr_t>>;
493 using chunks_iter_t = chunks_t::iterator;
495 struct block_meta_t
497 {
499 chunks_iter_t i_chunk;
500 };
501
506 size_t max_blocks_per_chunk;
508 chunks_t chunks;
510
511 chunks_iter_t i_stashed;
514 chunks_iter_t i_empty;
516 size_t next_capacity;
522 size_t block_size;
524
525 size_t extra_data;
527
528 public:
530 static yconstexpr const size_t min_block_size = sizeof(block_meta_t) + 1;
532
534 static yconstexpr const size_t default_capacity = yimpl(4);
536
537 static_assert(default_capacity > 1, "Invalid default value found.");
538
550 resource_pool(memory_resource&, size_t, size_t, size_t = 0,
551 size_t = default_capacity) ynothrowv;
553 resource_pool(resource_pool&&) ynothrow;
555 ~resource_pool();
557
562 resource_pool&
563 operator=(resource_pool&&) ynothrowv;
564
565 private:
567 YB_ATTR_nodiscard YB_PURE static block_meta_t&
568 access_meta(void* p, size_t blk_size) ynothrow
569 {
570 // NOTE: The types of the data members in %block_meta_t shall be decayed
571 // to avoid need of call to %std::launder which is not available before
572 // ISO C++17.
573 static_assert(is_decayed<id_t>(), "Invalid type found.");
574
575 yconstraint(p);
576
577 const auto p_meta(static_cast< block_meta_t*>(static_cast<void*>(
578 static_cast<byte*>(p) + blk_size - sizeof(block_meta_t))));
579
580 return *static_cast< block_meta_t*>(
581 yaligned(p_meta, yalignof(block_meta_t)));
582 }
583
584 public:
586 YB_ALLOCATOR YB_ATTR_returns_nonnull void*
587 allocate();
588
593 YB_ATTR_nodiscard YB_STATELESS static yconstfn size_t
594 adjust_for_block(size_t bytes, size_t alignment) ynothrow
595 {
596 return ystdex::max(bytes + sizeof(block_meta_t), alignment);
597 }
598
603 void
604 clear() ynothrow;
605
606 void
607 deallocate(void*) ynothrowv;
608
610 YB_ATTR_nodiscard YB_PURE size_t
611 get_block_size() const ynothrow
612 {
613 return block_size;
614 }
615
617 YB_ATTR_nodiscard YB_PURE size_t
618 get_capacity() const ynothrow
619 {
620 return next_capacity;
621 }
622
623 YB_ATTR_nodiscard YB_PURE size_t
624 get_extra_data() const ynothrow
625 {
626 return extra_data;
627 }
628
634 void
635 set_capacity(size_t cap) ynothrowv
636 {
637 yconstraint(cap > 1);
638 next_capacity = cap;
639 }
640
642 YB_ATTR_nodiscard YB_PURE memory_resource&
643 upstream() const ynothrowv
644 {
645 auto p(chunks.get_allocator().resource());
646
647 yassume(p);
648 return *p;
649 }
650 };
651
652
657 class YB_API oversized_map
658 : private yimpl(noncopyable), private yimpl(nonmovable)
659 {
660 public:
661 using mapped_type = std::pair<size_t, size_t>;
662 using map_type = std::unordered_map<void*, mapped_type, std::hash<void*>,
663 equal_to<>, polymorphic_allocator<std::pair<void* const,
664 mapped_type>>>;
665
666 private:
667 map_type entries;
668
669 public:
670 oversized_map(memory_resource& mem_rsrc)
671 : entries(&mem_rsrc)
672 {}
673 ~oversized_map();
674
675 YB_ATTR_nodiscard YB_PURE memory_resource&
676 upstream() ynothrowv
677 {
678 const auto p_upstream(entries.get_allocator().resource());
679
680 yassume(p_upstream);
681 return *p_upstream;
682 }
683
684 YB_ALLOCATOR YB_ATTR_returns_nonnull void*
685 allocate(size_t, size_t);
686
687 void
688 deallocate(void*, size_t, size_t) yimpl(ynothrowv);
689
690 void
691 release() ynothrow;
692 };
694
695
703 class YB_API pool_resource : public memory_resource
704 {
705 private:
706 using pools_t
707 = std::vector<resource_pool, polymorphic_allocator<resource_pool>>;
708
709 pool_options saved_options;
711 oversized_map oversized;
712 pools_t pools;
713
714 public:
720 pool_resource() ynothrow
721 : pool_resource(pool_options(), get_default_resource())
722 {}
724 YB_NONNULL(3)
725 pool_resource(const pool_options&, memory_resource*) ynothrow;
727 explicit
728 pool_resource(memory_resource* upstream)
729 : pool_resource(pool_options(), upstream)
730 {}
731 explicit
732 pool_resource(const pool_options& opts)
733 : pool_resource(opts, get_default_resource())
734 {}
736 ~pool_resource() override;
737
738 void
739 release() yimpl(ynothrow);
740
741 YB_ATTR_nodiscard YB_ATTR_returns_nonnull YB_PURE memory_resource*
742 upstream_resource() const yimpl(ynothrow)
743 {
744 return pools.get_allocator().resource();
745 }
746
747 YB_ATTR_nodiscard YB_PURE pool_options
748 options() const yimpl(ynothrow)
749 {
750 return saved_options;
751 }
752
753 protected:
754 YB_ALLOCATOR YB_ATTR_returns_nonnull void*
755 do_allocate(size_t, size_t) override;
756
757 void
758 do_deallocate(void*, size_t, size_t) yimpl(ynothrowv) override;
759
760 YB_ATTR_nodiscard yimpl(YB_STATELESS) bool
761 do_is_equal(const memory_resource&) const ynothrow override;
762
763 private:
764 YB_ATTR_nodiscard YB_PURE std::pair<pools_t::iterator, size_t>
765 find_pool(size_t, size_t) ynothrow;
766
767 YB_ATTR_nodiscard YB_PURE bool
768 pool_exists(const std::pair<pools_t::iterator, size_t>&) ynothrow;
769
770 YB_ATTR_nodiscard YB_PURE memory_resource&
771 upstream() ynothrowv
772 {
773 const auto p_upstream(upstream_resource());
774
775 yassume(p_upstream);
776 return *p_upstream;
777 }
778 };
780
781 inline namespace cpp2017
782 {
783
784 // XXX: %std::pmr::synchronized_pool_resource and
785 // %std::pmr::unsynchronized_pool_resource can be monotonic until %release or
786 // destruction. Although they are not both in %std implementation of Microsoft
787 // VC++ 15.8.2 and in %ystdex where both implement deallocation of upstream
788 // blocks in %do_deallocate, this is not specified by ISO C++.
789
790 #if YB_Has_memory_resource == 1
791 using std::pmr::synchronized_pool_resource;
792 using std::pmr::unsynchronized_pool_resource;
793 using std::pmr::monotonic_buffer_resource;
794 #else
795
797 class YB_API synchronized_pool_resource : yimpl(public pool_resource)
799 {
800 private:
801 using mutex = YB_Impl_mutex_ns::mutex;
802 template<typename _tMutex>
803 using lock_guard = YB_Impl_mutex_ns::lock_guard<_tMutex>;
804
805 mutable mutex mtx{};
806
807 public:
808 yimpl(using) pool_resource::pool_resource;
810 ~synchronized_pool_resource() override;
811
812 void
813 release() yimpl(ynothrow)
814 {
815 lock_guard<mutex> gd(mtx);
816
817 pool_resource::release();
818 }
819
820 protected:
821 YB_ALLOCATOR YB_ATTR_returns_nonnull void*
822 do_allocate(size_t bytes, size_t alignment) override
823 {
824 lock_guard<mutex> gd(mtx);
825
826 return pool_resource::do_allocate(bytes, alignment);
827 }
828
829 void
830 do_deallocate(void* p, size_t bytes, size_t alignment) yimpl(ynothrowv)
831 override
832 {
833 lock_guard<mutex> gd(mtx);
834
835 pool_resource::do_deallocate(p, bytes, alignment);
836 }
837 };
838
839
840 yimpl(using) unsynchronized_pool_resource = pool_resource;
841
842
844 class YB_API monotonic_buffer_resource : public memory_resource,
845 private yimpl(noncopyable), private yimpl(nonmovable)
846 {
847 private:
848 struct chunks_t;
849 memory_resource* upstream_rsrc;
850 void* current_buffer = {};
851 size_t next_buffer_size;
852 size_t space_available = 0;
853 ystdex::aligned_storage_t<16> chunks_data{};
855 pun_ref<chunks_t> pun;
856
857 public:
859
860 monotonic_buffer_resource()
861 : monotonic_buffer_resource(get_default_resource())
862 {}
863 explicit
864 monotonic_buffer_resource(memory_resource*) yimpl(ynothrow);
865 monotonic_buffer_resource(size_t, memory_resource*) yimpl(ynothrow);
866 monotonic_buffer_resource(void*, size_t, memory_resource*) yimpl(ynothrow);
867 explicit
868 monotonic_buffer_resource(size_t initial_size) yimpl(ynothrow)
869 : monotonic_buffer_resource(initial_size, get_default_resource())
870 {}
871 monotonic_buffer_resource(void* buffer, size_t buffer_size) yimpl(ynothrow)
872 : monotonic_buffer_resource(buffer, buffer_size, get_default_resource())
873 {}
875 ~monotonic_buffer_resource() override;
876
877 void
878 release() yimpl(ynothrow);
879
880 YB_ATTR_nodiscard YB_ATTR_returns_nonnull YB_PURE memory_resource*
881 upstream_resource() const yimpl(ynothrow)
882 {
883 return upstream_rsrc;
884 }
885
886 protected:
887 YB_ALLOCATOR YB_ATTR_returns_nonnull void*
888 do_allocate(size_t, size_t) override;
889
891 void
892 do_deallocate(void*, size_t, size_t) override
893 {}
894
895 YB_ATTR_nodiscard yimpl(YB_STATELESS) bool
896 do_is_equal(const memory_resource&) const ynothrow override;
897 };
899
900 # undef YB_Impl_mutex_ns
901
902 #endif
903
904 } // inline namespace cpp2017;
905
906 } // namespace pmr;
907
908 } // namespace ystdex;
909
910 #endif
911
ystdex::pmr::pool_resource
池资源。
Definition: memory_resource.h:704
YSLib::Drawing::buffer
The boundary is out of the buffer
Definition: YDraw.h:118
ystdex::pmr::cpp2017::memory_resource::~memory_resource
virtual ~memory_resource()
虚析构：类定义外默认实现。
ystdex::pmr::cpp2017::monotonic_buffer_resource::monotonic_buffer_resource
monotonic_buffer_resource(size_t, memory_resource *)
ystdex::pmr::resource_pool::upstream
memory_resource & upstream() const
Definition: memory_resource.h:643
YB_ATTR_nodiscard
#define YB_ATTR_nodiscard
标记返回值不被忽略的属性。
Definition: ydef.h:715
ystdex::pmr::resource_pool::adjust_for_block
static size_t adjust_for_block(size_t bytes, size_t alignment)
调整分配空间大小以适应块。
Definition: memory_resource.h:594
ystdex::pmr::cpp2017::memory_resource::is_equal
bool is_equal(const memory_resource &other) const
Definition: memory_resource.h:235
ystdex::pmr::cpp2017::monotonic_buffer_resource::~monotonic_buffer_resource
~monotonic_buffer_resource() override
ystdex::details::get_size_of_n
size_t get_size_of_n(size_t n)
Definition: memory_resource.h:141
ystdex::pmr::pool_resource::do_is_equal
bool do_is_equal(const memory_resource &) const override
ystdex::pmr::resource_pool::block_size
size_t block_size
分配块大小。
Definition: memory_resource.h:522
ystdex::pmr::polymorphic_allocator::polymorphic_allocator
polymorphic_allocator(const polymorphic_allocator< _tOther > &other)
Definition: memory_resource.h:298
ystdex::pmr::oversized_map::oversized_map
oversized_map(memory_resource &mem_rsrc)
Definition: memory_resource.h:670
ystdex::pmr::polymorphic_allocator::operator=
polymorphic_allocator & operator=(const polymorphic_allocator &)=delete
ystdex::pmr::cpp2017::monotonic_buffer_resource::monotonic_buffer_resource
monotonic_buffer_resource(void *buffer, size_t buffer_size)
Definition: memory_resource.h:871
ystdex::pmr::cpp2017::monotonic_buffer_resource::monotonic_buffer_resource
monotonic_buffer_resource()
Definition: memory_resource.h:860
yconstexpr
#define yconstexpr
指定编译时常量表达式。
Definition: ydef.h:1072
ystdex::pmr::resource_pool
资源池。
Definition: memory_resource.h:480
base.h
基类实用设施。
ystdex::pmr::cpp2017::monotonic_buffer_resource
Definition: memory_resource.h:846
YB_PURE
#define YB_PURE
指示函数或函数模板实例为纯函数。
Definition: ydef.h:919
list.hpp
列表容器。
ystdex::pmr::oversized_map::upstream
memory_resource & upstream()
Definition: memory_resource.h:676
ystdex::pmr::resource_pool::i_empty
chunks_iter_t i_empty
快速待分配空块迭代器。
Definition: memory_resource.h:514
yalignof
#define yalignof(_type)
指定特定类型的对齐。
Definition: ydef.h:1053
YSLib::Drawing::r
The boundary is out of the const Graphics const Rect const Point const Point Color c const Rect const Rect & r
Definition: YDraw.h:174
ystdex::pmr::resource_pool::max_blocks_per_chunk
size_t max_blocks_per_chunk
块中最大区块数。
Definition: memory_resource.h:506
ystdex::pmr::pool_resource::pool_exists
bool pool_exists(const std::pair< pools_t::iterator, size_t > &)
ystdex::dep_ops::equality_comparable
_t< details::ops_seq< _type, _type2, _tOpt, cond_t< is_same< _type, _type2 >, index_sequence< 7 >, index_sequence< 6, 7, 8 > >> > equality_comparable
Definition: operators.hpp:265
ystdex::pmr::polymorphic_allocator::deallocate
void deallocate(_type *p, size_t n)
Definition: memory_resource.h:315
ystdex::pmr::polymorphic_allocator::deallocate_object
void deallocate_object(_tObj *p, size_t n=1)
Definition: memory_resource.h:350
platform::size_t
YB_ATTR_nodiscard YF_API size_t
Definition: FileIO.h:1345
ystdex::cpp2014::aligned_storage_t
typename aligned_storage< _vLen, _vAlign >::type aligned_storage_t
Definition: meta.hpp:187
ystdex::pmr::pool_resource::pools
pools_t pools
Definition: memory_resource.h:712
ystdex::pmr::cpp2017::unsynchronized_pool_resource
pool_resource unsynchronized_pool_resource
Definition: memory_resource.h:840
ystdex::cpp2014::equal_to<>
ystdex::pmr::cpp2017::set_default_resource
memory_resource * set_default_resource(memory_resource *)
Definition: memory_resource.cpp:201
ystdex::cpp2014::max
const _type & max(const _type &a, const _type &b, _fComp comp=less< _type >())
取较大的元素。
Definition: algorithm.hpp:635
ystdex::pmr::cpp2017::memory_resource::memory_resource
memory_resource(const memory_resource &)=default
ystdex::pmr::polymorphic_allocator::memory_rsrc
memory_resource * memory_rsrc
Definition: memory_resource.h:282
ystdex::pmr::polymorphic_allocator::construct
void construct(_tObj *p, _tParams &&... args)
Definition: memory_resource.h:387
ystdex::pmr::cpp2017::memory_resource::do_deallocate
virtual void do_deallocate(void *, size_t, size_t)=0
ystdex::pmr::polymorphic_allocator::polymorphic_allocator
polymorphic_allocator()
Definition: memory_resource.h:285
ystdex::pmr::cpp2017::synchronized_pool_resource::do_deallocate
void do_deallocate(void *p, size_t bytes, size_t alignment) override
Definition: memory_resource.h:830
ystdex::pmr::cpp2017::monotonic_buffer_resource::do_is_equal
bool do_is_equal(const memory_resource &) const override
ystdex::pmr::cpp2017::monotonic_buffer_resource::do_deallocate
void do_deallocate(void *, size_t, size_t) override
Definition: memory_resource.h:892
ystdex::details::get_size_of_n< 1 >
size_t get_size_of_n< 1 >(size_t n)
Definition: memory_resource.h:149
ystdex::pmr::polymorphic_allocator::new_object
_tObj * new_object(_tCtorParams &&... ctor_args)
Definition: memory_resource.h:357
ystdex::is_decayed
判断指定类型是否已退化为指定类型。
Definition: meta.hpp:672
ystdex::pmr::pool_resource::saved_options
pool_options saved_options
Definition: memory_resource.h:709
CHRLib::args
YB_ATTR_nodiscard _tParams && args
Definition: CharacterProcessing.h:649
ystdex::pmr::cpp2017::new_delete_resource
memory_resource * new_delete_resource()
Definition: memory_resource.cpp:64
yassume
#define yassume(_expr)
假定：环境语义。
Definition: cassert.h:96
ystdex::pmr::cpp2017::monotonic_buffer_resource::upstream_rsrc
memory_resource * upstream_rsrc
Definition: memory_resource.h:848
ystdex::pmr::resource_pool::get_capacity
size_t get_capacity() const
Definition: memory_resource.h:618
ystdex::bases::nonmovable
不可转移对象：禁止继承此类的对象调用默认原型的转移构造函数和转移赋值操作符。
Definition: base.h:90
ystdex::pmr::oversized_map::entries
map_type entries
Definition: memory_resource.h:667
ystdex::pmr::cpp2017::monotonic_buffer_resource::monotonic_buffer_resource
monotonic_buffer_resource(size_t initial_size)
Definition: memory_resource.h:868
YB_ATTR_returns_nonnull
#define YB_ATTR_returns_nonnull
指示返回非空属性。
Definition: ydef.h:761
CHRLib::CharSet::other
@ other
Definition: Encoding.h:65
YB_ALLOCATOR
#define YB_ALLOCATOR
指示返回指针的函数或函数模板若为非空值则对应的存储不和其它对象指针共享别名。
Definition: ydef.h:785
ystdex::pmr::resource_pool::block_meta_t::i_chunk
chunks_iter_t i_chunk
Definition: memory_resource.h:499
ystdex::pmr::operator==
bool operator==(const polymorphic_allocator< _type1 > &a, const polymorphic_allocator< _type2 > &b)
Definition: memory_resource.h:408
ystdex::pmr::cpp2017::memory_resource::memory_resource
memory_resource()=default
ystdex::pmr::cpp2017::memory_resource
存储资源。
Definition: memory_resource.h:180
ystdex::pmr::polymorphic_allocator::allocate_object
_tObj * allocate_object(size_t n=1)
Definition: memory_resource.h:340
ystdex::pmr::oversized_map::map_type
std::unordered_map< void *, mapped_type, std::hash< void * >, equal_to<>, polymorphic_allocator< std::pair< void *const, mapped_type > >> map_type
Definition: memory_resource.h:664
yforward
#define yforward(_expr)
根据参数类型使用 std::forward 转发对应参数。
Definition: ydef.h:1508
ystdex::pmr::oversized_map
超出池内分配的资源映射。
Definition: memory_resource.h:659
ystdex::pmr::resource_pool::chunks
chunks_t chunks
被池所有的块。
Definition: memory_resource.h:508
ystdex::pmr::cpp2017::null_memory_resource
memory_resource * null_memory_resource()
Definition: memory_resource.cpp:164
ystdex::pmr::pool_resource::upstream
memory_resource & upstream()
Definition: memory_resource.h:771
YB_STATELESS
#define YB_STATELESS
指示函数或函数模板实例为无状态函数。
Definition: ydef.h:941
ystdex::pmr::cpp2017::pool_options
Definition: memory_resource.h:452
ystdex::pmr::cpp2017::memory_resource::do_is_equal
virtual bool do_is_equal(const memory_resource &) const =0
operators.hpp
重载操作符。
ystdex::pmr::cpp2017::synchronized_pool_resource
Definition: memory_resource.h:799
ystdex::pmr::polymorphic_allocator::delete_object
void delete_object(_tObj *p)
Definition: memory_resource.h:374
memory.hpp
存储和智能指针特性。
ystdex::pmr::polymorphic_allocator::value_type
_type value_type
Definition: memory_resource.h:278
ystdex::pmr::pool_resource::release
void release()
Definition: memory_resource.cpp:672
ystdex::pmr::pool_resource::pool_resource
pool_resource(const pool_options &opts)
Definition: memory_resource.h:732
pseudo_mutex.h
伪互斥量。
ystdex::pmr::pool_resource::find_pool
std::pair< pools_t::iterator, size_t > find_pool(size_t, size_t)
ystdex::pmr::polymorphic_allocator::select_on_container_copy_construction
polymorphic_allocator select_on_container_copy_construction() const
Definition: memory_resource.h:394
ystdex::pmr::polymorphic_allocator::deallocate_bytes
void deallocate_bytes(void *p, size_t nbytes, size_t alignment=std::alignment_of< std::max_align_t >::value)
Definition: memory_resource.h:333
ystdex::pmr::oversized_map::mapped_type
std::pair< size_t, size_t > mapped_type
Definition: memory_resource.h:661
yconstraint
#define yconstraint(_expr)
约束：接口语义。
Definition: cassert.h:125
ystdex::pmr::resource_pool::chunk_t
Definition: memory_resource.cpp:409
ystdex::pmr::cpp2017::monotonic_buffer_resource::do_allocate
void * do_allocate(size_t, size_t) override
ystdex::pmr::resource_pool::block_meta_t
保存在块末尾的元数据类型。
Definition: memory_resource.h:497
yaligned
#define yaligned(_p, _align)
假定指定指针值按指定对齐值对齐。
Definition: placement.hpp:140
ystdex::pmr::cpp2017::monotonic_buffer_resource::monotonic_buffer_resource
monotonic_buffer_resource(void *, size_t, memory_resource *)
ystdex::uninitialized_construct_using_allocator
_type * uninitialized_construct_using_allocator(_type *p, const _tAlloc &a, _tParams &&... args)
Definition: allocator.hpp:351
ystdex::pmr::operator!=
bool operator!=(const polymorphic_allocator< _type1 > &a, const polymorphic_allocator< _type2 > &b)
Definition: memory_resource.h:416
type_pun.hpp
共享存储和直接转换。
ystdex::pmr::resource_pool::chunk_pr_t
std::pair< id_t, chunk_t > chunk_pr_t
块存储对类型。
Definition: memory_resource.h:487
ystdex::pmr::cpp2017::get_default_resource
memory_resource * get_default_resource()
Definition: memory_resource.cpp:209
ystdex::pmr::pool_resource::pool_resource
pool_resource()
Definition: memory_resource.h:720
ystdex::pmr::adjust_pool_options
void adjust_pool_options(pool_options &)
修改池选项的默认值。
Definition: memory_resource.cpp:333
YB_API
#define YB_API
YBase 应用程序编程接口：用于向库文件约定链接。
Definition: ydef.h:985
ystdex::pmr::resource_pool::chunks_iter_t
chunks_t::iterator chunks_iter_t
\build 块集合迭代器类型。
Definition: memory_resource.h:493
ystdex::pmr::pool_resource::options
pool_options options() const
Definition: memory_resource.h:748
ystdex::pmr::cpp2017::memory_resource::do_allocate
virtual void * do_allocate(size_t, size_t)=0
YB_ATTR_novtable
#define YB_ATTR_novtable
修饰类定义要求实现不生成初始化动态类型信息。
Definition: ydef.h:745
ystdex::pmr::cpp2017::monotonic_buffer_resource::release
void release()
ynothrowv
#define ynothrowv
YSLib 无异常抛出保证验证：有条件地使用无异常抛出规范。
Definition: ydef.h:1219
ystdex
<memory> 特性测试宏。
Definition: ydef.h:1262
ystdex::pmr::pool_resource::~pool_resource
~pool_resource() override
ystdex::pmr::cpp2017::memory_resource::allocate
void * allocate(size_t bytes, size_t alignment=max_align)
Definition: memory_resource.h:211
ystdex::pmr::polymorphic_allocator::resource
memory_resource * resource() const
Definition: memory_resource.h:400
ystdex::pmr::pool_resource::do_deallocate
void do_deallocate(void *, size_t, size_t) override
Definition: memory_resource.cpp:695
ystdex::pmr::polymorphic_allocator::polymorphic_allocator
polymorphic_allocator(const polymorphic_allocator &other)=default
ystdex::pmr::cpp2017::memory_resource::deallocate
void deallocate(void *p, size_t bytes, size_t alignment=max_align)
Definition: memory_resource.h:227
YSLib::_tParams
YB_ATTR_nodiscard YB_PURE typename _tParams
Definition: ValueNode.h:1294
ystdex::pmr::cpp2017::monotonic_buffer_resource::next_buffer_size
size_t next_buffer_size
Definition: memory_resource.h:851
ystdex::pmr::polymorphic_allocator::allocate
_type * allocate(size_t n)
Definition: memory_resource.h:308
alignment
size_t alignment
Definition: memory_resource.cpp:296
ystdex::pmr::cpp2017::synchronized_pool_resource::lock_guard
std ::lock_guard< _tMutex > lock_guard
Definition: memory_resource.h:803
ystdex::pmr::cpp2017::memory_resource::operator==
friend bool operator==(const memory_resource &a, const memory_resource &b)
Definition: memory_resource.h:201
ystdex::pmr::cpp2017::monotonic_buffer_resource::pun
pun_ref< chunks_t > pun
Definition: memory_resource.h:855
ystdex::pmr::polymorphic_allocator::allocate_bytes
void * allocate_bytes(size_t nbytes, size_t alignment=std::alignment_of< std::max_align_t >::value)
Definition: memory_resource.h:327
ystdex::pmr::pool_resource::pools_t
std::vector< resource_pool, polymorphic_allocator< resource_pool > > pools_t
Definition: memory_resource.h:707
ystdex::pun_ref< chunks_t >
platform::p
return p p
Definition: YCLib/FileSystem.h:209
ystdex::pmr::cpp2017::synchronized_pool_resource::mutex
std ::mutex mutex
Definition: memory_resource.h:801
const
const Decapsulate const Decapsulate &y ynothrow ContextNode &ctx const
Definition: NPLA1Forms.cpp:1629
yimpl
#define yimpl(...)
实现标签。
Definition: ydef.h:413
ystdex::pmr::pool_resource::oversized
oversized_map oversized
Definition: memory_resource.h:711
ystdex::pmr::cpp2017::synchronized_pool_resource::do_allocate
void * do_allocate(size_t bytes, size_t alignment) override
Definition: memory_resource.h:822
ystdex::pmr::resource_pool::get_extra_data
size_t get_extra_data() const
Definition: memory_resource.h:624
ynothrow
#define ynothrow
YSLib 无异常抛出保证：若支持 noexcept 关键字， 指定特定的 noexcept 异常规范。
Definition: ydef.h:1199
ystdex::is_power_of_2_positive
bool is_power_of_2_positive(std::uintmax_t n)
判断无符号整数是否为 2 的整数次幂的正整数。
Definition: cstdint.hpp:280
ystdex::bases::noncopyable
不可复制对象：禁止派生类调用默认原型的复制构造函数和复制赋值操作符。
Definition: base.h:50
ystdex::pmr::cpp2017::monotonic_buffer_resource::monotonic_buffer_resource
monotonic_buffer_resource(memory_resource *)
ystdex::pmr::resource_pool::id_t
size_t id_t
块标识类型。
Definition: memory_resource.h:485
ystdex::cpp2017::destroy
void destroy(_tFwd first, _tFwd last)
Definition: placement.hpp:451
ystdex::list::get_allocator
allocator_type get_allocator() const
Definition: list.hpp:1225
ystdex::pmr::pool_resource::do_allocate
void * do_allocate(size_t, size_t) override
Definition: memory_resource.cpp:679
ystdex::list< chunk_pr_t, polymorphic_allocator< chunk_pr_t > >
ystdex::pmr::resource_pool::set_capacity
void set_capacity(size_t cap)
设置下一个分配块使用的区块容量。
Definition: memory_resource.h:635
yconstfn
#define yconstfn
指定编译时常量函数。
Definition: ydef.h:1073
ystdex::list::iterator
typename rep_type::iterator iterator
Definition: list.hpp:1081
ystdex::pmr::polymorphic_allocator
多态分配器。
Definition: memory_resource.h:276
YSLib::a
YB_PURE const _type * a
Definition: YCoreUtilities.h:168
cstdint.hpp
ISO C 标准整数类型和相关扩展操作。
algorithm.hpp
泛型算法。