NUMA++ 0.11.0
Loading...
Searching...
No Matches
allocExample.cpp
1#include <numapp/memory.hpp>
3
4void* BindAlloc(std::size_t size, int node, std::error_code& ec) {
5 using namespace numapp;
6
8 void* ptr = Allocate(size, policy, MemPolicyFlag::Strict, ec);
9 if (ec) {
10 return nullptr;
11 }
12 ec = MemLock(ptr, size, LockFlag::PreFault);
13 if (ec) {
14 return nullptr;
15 }
16 return ptr;
17}
Class representing a memory policy that can be modified and used to apply to the current thread or a ...
static MemPolicy MakeBindNode(int node)
Creates a strict policy (using MPOL_BIND) to allocate all memory to the specified node.
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
void * Allocate(std::size_t size, MemPolicy const &policy, std::error_code &ec) noexcept
See group for details.
Definition memory.cpp:87
@ PreFault
Locks pages whether they are resident or not.
Definition memory.hpp:126
Contains memory function declarations.
Contains declarations for numapp::MemPolicy.