VLink  2.0.0
A high-performance communication middleware
memory_resource.h File Reference

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

#include <memory>
Include dependency graph for memory_resource.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

 
 

Functions

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

Detailed Description

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);
Note
do_allocate throws std::bad_alloc when the underlying pool returns nullptr, satisfying the pmr contract. Equality is identity over the bound MemoryPool object.