NUMA++ 0.11.0
Loading...
Searching...
No Matches
mempolicyExample2.cpp
1#include <iostream>
2#include <numapp/memory.hpp>
4
5void BindMemoryRange(int node, void* address, std::size_t size) {
7 using numapp::operator|;
10
11 auto policy = MemPolicy::MakeBindNode(node);
12 auto flags = MemPolicyFlag::Move | MemPolicyFlag::Strict;
13
14 if (auto ec = numapp::Apply(address, size, policy, flags); ec) {
15 std::cerr << "Failed to apply policy: " << ec.message() << std::endl;
16 throw std::system_error(ec);
17 }
18
19 if (auto ec = numapp::MemLock(address, size, LockFlag::PreFault); ec) {
20 std::cerr << "Failed to apply policy: " << ec.message() << std::endl;
21 throw std::system_error(ec);
22 }
23}
Class representing a memory policy that can be modified and used to apply to the current thread or a ...
std::error_code Apply(pid_t thread, CpuAffinity const &affinity) noexcept
Apply policy to specified thread.
std::error_code MemLock(void const *addr, std::size_t len, LockFlag flag) noexcept
Lock memory pages in the specified address range.
Definition memory.cpp:58
MemPolicyFlag
Flag that modify the behaviour of applying a memory policy to a range of memory.
Definition mempolicy.hpp:36
LockFlag
Mutually exclusive flags that modifies behaviour of MemLock().
Definition memory.hpp:119
Contains memory function declarations.
Contains declarations for numapp::MemPolicy.