VLink  2.0.0
A high-performance communication middleware
memory_resource.h 文件参考

PMR adapter that lets standard pmr-aware containers allocate through vlink::MemoryPool. 更多...

#include <memory>
memory_resource.h 的引用(Include)关系图:
此图展示该文件直接或间接的被哪些文件引用了:

浏览源代码.

命名空间

 
 

函数

template<typename T , typename... Args>
std::shared_ptr< T > vlink::MemoryResource::make_shared (Args &&... args)
 Fallback make_shared forwarding to std::make_shared. 更多...
 
template<typename T , typename... Args>
std::unique_ptr< T > vlink::MemoryResource::make_unique (Args &&... args)
 Fallback make_unique forwarding to std::make_unique. 更多...
 

详细描述

PMR adapter that lets standard pmr-aware containers allocate through vlink::MemoryPool.

vlink::MemoryResource derives from std::pmr::memory_resource and forwards each request onto an owned (or shared) vlink::MemoryPool. This bridges the standard polymorphic allocator machinery with VLink's tiered pool.

PMR vs VLink resources
Aspect std::pmr::new_delete_resource vlink::MemoryResource
Backing allocator global operator new / delete vlink::MemoryPool (per-tier free lists)
Allocation footprint unpredictable per-call bounded per-tier; pooled
Concurrent allocs global allocator scaling per-tier locking, low contention
Bypass mode not applicable empty tier list yields pass-through
Maintenance not applicable trim releases idle chunks
Lifetime
  • MemoryResource(), MemoryResource(int) and MemoryResource(const Config&) each heap-allocate a private MemoryPool and own it for the lifetime of the resource.
  • MemoryResource::global_instance returns a process-wide singleton that wraps MemoryPool::global_instance; the resource is not deleted by the destructor.
Example
// Shared process-wide resource.
std::pmr::vector<int> v(&vlink::MemoryResource::global_instance());
v.reserve(1024);
// Private level-3 pyramid:
std::pmr::polymorphic_allocator<char> alloc(&res);
std::pmr::string s(alloc);
// Private resource with a custom tier list and full-quota preallocation.
cfg.tiers = {{64, 16}, {1024, 4}};
cfg.prealloc = true;
std::pmr::vector<double> w(&custom);
注解
do_allocate throws std::bad_alloc when the underlying pool returns nullptr, satisfying the pmr contract. Equality is identity over the bound MemoryPool object.