NUMA++ 0.11.0
Loading...
Searching...
No Matches
pageResourceExample.cpp
1#include <string>
2#include <vector>
3
4#include <numapp/memory.hpp>
5
6void Example() {
7 // Create a pool resource that allocates memory from NUMA node 1 with using
8 // PageResource.
10 numapp::MemPolicyFlag::Strict);
11
12 // Important Note
13 // --------------
14 //
15 // Pool resource likely requires memory for its implementation, which will
16 // use the same upstream memory resource `resource`. This is not necessarily
17 // optimal as the pool implementation may perform multiple allocations, each
18 // smaller than the page size, which will each take at minimum 1 page. This
19 // overhead may be discounted by example sharing the pool resource for the
20 // full application, or per NUMA node.
21 auto pool = std::pmr::unsynchronized_pool_resource(&resource);
22
23 // Now we can use the `pool` with e.g. STL containers that use
24 // `std::pmr::polymorphic_allocator`
25 [[maybe_unused]] auto vector = std::pmr::vector<std::uint8_t>(1024, &pool);
26 [[maybe_unused]] auto string = std::pmr::string(1024, 'a', &pool);
27}
static MemPolicy MakeBindNode(int node)
Creates a strict policy (using MPOL_BIND) to allocate all memory to the specified node.
Polymorphic memory resource allocating full system pages with specified NUMA policy.
Definition memory.hpp:359
Contains memory function declarations.