NUMA++ 0.12.0
Loading...
Searching...
No Matches
allocExample.cpp
Go to the documentation of this file.
1/**
2 * @file
3 * @copyright
4 * SPDX-FileCopyrightText: 2023-2023 European Southern Observatory (ESO)
5 *
6 * SPDX-License-Identifier: LGPL-3.0-only
7 */
8#include <numapp/memory.hpp>
10
11void* BindAlloc(std::size_t size, int node, std::error_code& ec) {
12 using namespace numapp;
13
15 void* ptr = Allocate(size, policy, MemPolicyFlag::Strict, ec);
16 if (ec) {
17 return nullptr;
18 }
19 ec = MemLock(ptr, size, LockFlag::PreFault);
20 if (ec) {
21 return nullptr;
22 }
23 return ptr;
24}
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:60
void * Allocate(std::size_t size, MemPolicy const &policy, std::error_code &ec) noexcept
See group for details.
Definition memory.cpp:89
@ PreFault
Locks pages whether they are resident or not.
Definition memory.hpp:128
Contains memory function declarations.
Contains declarations for numapp::MemPolicy.