memory_resource
标准库头<内存[医]资源>
班
在命名空间PMR中定义
*。
多态[医]分配器%28C++17%29基于std::内存支持运行时多态性的分配器[医]资源它是用%28类模板%29构造的。
记忆[医]资源%28C++17%29封装内存资源%28class%29的类的抽象接口
水池[医]选项%28C++17%29池资源的一组构造函数选项%28class%29
同步[医]水池[医]资源%28C++17%29一个线程安全的STD::pmr::内存[医]用于管理不同块大小的池中分配的资源%28class%29
不同步[医]水池[医]资源%28C++17%29 a线程-不安全的std::pmr::内存[医]用于管理不同块大小的池中分配的资源%28class%29
单调[医]缓冲器[医]资源%28C++17%29一个特殊用途的std::pmr::Memory[医]只在资源被销毁时释放分配内存的资源%28class%29
功能
在命名空间PMR中定义
*。
新[医]删除[医]资源%28C++17%29返回一个静态程序范围的std::pmr::Memory[医]使用全局运算符New和Operator DELETE分配和释放内存%28功能%29的资源
零[医]记忆[医]资源%28C++17%29返回静态std::pmr::Memory[医]不执行分配%28功能%29的资源
弄到[医]违约[医]资源%28C++17%29获取默认的std::pmr::内存[医]资源%28功能%29
集[医]违约[医]资源%28C++17%29设置默认的std::pmr::内存[医]资源%28功能%29
简介
二次
namespace std::pmr {
// class memory_resource
class memory_resource;
bool operator==(const memory_resource& a, const memory_resource& b) noexcept;
bool operator!=(const memory_resource& a, const memory_resource& b) noexcept;
// class template polymorphic_allocator
template <class Tp> class polymorphic_allocator;
template <class T1, class T2>
bool operator==(const polymorphic_allocator<T1>& a,
const polymorphic_allocator<T2>& b) noexcept;
template <class T1, class T2>
bool operator!=(const polymorphic_allocator<T1>& a,
const polymorphic_allocator<T2>& b) noexcept;
// global memory resources
memory_resource* new_delete_resource() noexcept;
memory_resource* null_memory_resource() noexcept;
memory_resource* set_default_resource(memory_resource* r) noexcept;
memory_resource* get_default_resource() noexcept;
// pool resource classes
struct pool_options;
class synchronized_pool_resource;
class unsynchronized_pool_resource;
class monotonic_buffer_resource;
}
二次
类std::pmr::memory_resource
二次
class memory_resource {
static constexpr size_t max_align = alignof(max_align_t // exposition only
public:
virtual ~memory_resource(
void* allocate(size_t bytes, size_t alignment = max_align
void deallocate(void* p, size_t bytes, size_t alignment = max_align
bool is_equal(const memory_resource& other) const noexcept;
private:
virtual void* do_allocate(size_t bytes, size_t alignment) = 0;
virtual void do_deallocate(void* p, size_t bytes, size_t alignment) = 0;
virtual bool do_is_equal(const memory_resource& other) const noexcept = 0;
};
二次
类模板std::pmr::polymorphic_allocator
二次
template <class Tp>
class polymorphic_allocator {
memory_resource* memory_rsrc; // exposition only
public:
using value_type = Tp;
// constructors
polymorphic_allocator() noexcept;
polymorphic_allocator(memory_resource* r
polymorphic_allocator(const polymorphic_allocator& other) = default;
template <class U>
polymorphic_allocator(const polymorphic_allocator<U>& other) noexcept;
polymorphic_allocator&
operator=(const polymorphic_allocator& rhs) = delete;
// member functions
Tp* allocate(size_t n
void deallocate(Tp* p, size_t n
template <class T, class... Args>
void construct(T* p, Args&&... args
template <class T1, class T2, class... Args1, class... Args2>
void construct(pair<T1,T2>* p, piecewise_construct_t,
tuple<Args1...> x, tuple<Args2...> y
template <class T1, class T2>
void construct(pair<T1,T2>* p
template <class T1, class T2, class U, class V>
void construct(pair<T1,T2>* p, U&& x, V&& y
template <class T1, class T2, class U, class V>
void construct(pair<T1,T2>* p, const pair<U, V>& pr
template <class T1, class T2, class U, class V>
void construct(pair<T1,T2>* p, pair<U, V>&& pr
template <class T>
void destroy(T* p
polymorphic_allocator select_on_container_copy_construction() const;
memory_resource* resource() const;
};
二次
类std::pmr::pool_options
二次
struct pool_options {
size_t max_blocks_per_chunk = 0;
size_t largest_required_pool_block = 0;
};
二次
类std::pmr::synchronized_pool_resource
二次
class synchronized_pool_resource : public memory_resource {
public:
synchronized_pool_resource(const pool_options& opts,
memory_resource* upstream
synchronized_pool_resource()
: synchronized_pool_resource(pool_options(), get_default_resource()) {}
explicit synchronized_pool_resource(memory_resource* upstream)
: synchronized_pool_resource(pool_options(), upstream) {}
explicit synchronized_pool_resource(const pool_options& opts)
: synchronized_pool_resource(opts, get_default_resource()) {}
synchronized_pool_resource(const synchronized_pool_resource&) = delete;
virtual ~synchronized_pool_resource(
synchronized_pool_resource&
operator=(const synchronized_pool_resource&) = delete;
void release(
memory_resource* upstream_resource() const;
pool_options options() const;
protected:
void *do_allocate(size_t bytes, size_t alignment) override;
void do_deallocate(void *p, size_t bytes, size_t alignment) override;
bool do_is_equal(const memory_resource& other) const noexcept override;
};
二次
类std::pmr::unsynchronized_pool_resource
二次
class unsynchronized_pool_resource : public memory_resource {
public:
unsynchronized_pool_resource(const pool_options& opts,
memory_resource* upstream
unsynchronized_pool_resource()
: unsynchronized_pool_resource(pool_options(), get_default_resource()) {}
explicit unsynchronized_pool_resource(memory_resource* upstream)
: unsynchronized_pool_resource(pool_options(), upstream) {}
explicit unsynchronized_pool_resource(const pool_options& opts)
: unsynchronized_pool_resource(opts, get_default_resource()) {}
unsynchronized_pool_resource(const unsynchronized_pool_resource&) = delete;
virtual ~unsynchronized_pool_resource(
unsynchronized_pool_resource&
operator=(const unsynchronized_pool_resource&) = delete;
void release(
memory_resource *upstream_resource() const;
pool_options options() const;
protected:
void* do_allocate(size_t bytes, size_t alignment) override;
void do_deallocate(void* p, size_t bytes, size_t alignment) override;
bool do_is_equal(const memory_resource& other) const noexcept override;
};
二次
类std::pmr::monotonic_buffer_resource
二次
class monotonic_buffer_resource : public memory_resource {
memory_resource *upstream_rsrc; // exposition only
void *current_buffer; // exposition only
size_t next_buffer_size; // exposition only
public:
explicit monotonic_buffer_resource(memory_resource *upstream
monotonic_buffer_resource(size_t initial_size, memory_resource *upstream
monotonic_buffer_resource(void *buffer, size_t buffer_size,
memory_resource *upstream
monotonic_buffer_resource()
: monotonic_buffer_resource(get_default_resource()) {}
explicit monotonic_buffer_resource(size_t initial_size)
: monotonic_buffer_resource(initial_size, get_default_resource()) {}
monotonic_buffer_resource(void *buffer, size_t buffer_size)
: monotonic_buffer_resource(buffer, buffer_size, get_default_resource()) {}
monotonic_buffer_resource(const monotonic_buffer_resource&) = delete;
virtual ~monotonic_buffer_resource(
monotonic_buffer_resource
operator=(const monotonic_buffer_resource&) = delete;
void release(
memory_resource* upstream_resource() const;
protected:
void* do_allocate(size_t bytes, size_t alignment) override;
void do_deallocate(void* p, size_t bytes, size_t alignment) override;
bool do_is_equal(const memory_resource& other) const noexcept override;
};
二次
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。