NUMA++ 0.12.0
Loading...
Searching...
No Matches
pageResourceExample.cpp
Go to the documentation of this file.
1/**
2 * @file
3 * @copyright
4 * SPDX-FileCopyrightText: 2025-2025 European Southern Observatory (ESO)
5 *
6 * SPDX-License-Identifier: LGPL-3.0-only
7 */
8#include <string>
9#include <vector>
10
11#include <numapp/memory.hpp>
12
13void Example() {
14 // Create a pool resource that allocates memory from NUMA node 1 with using
15 // PageResource.
17 numapp::MemPolicyFlag::Strict);
18
19 // Important Note
20 // --------------
21 //
22 // Pool resource likely requires memory for its implementation, which will
23 // use the same upstream memory resource `resource`. This is not necessarily
24 // optimal as the pool implementation may perform multiple allocations, each
25 // smaller than the page size, which will each take at minimum 1 page. This
26 // overhead may be discounted by example sharing the pool resource for the
27 // full application, or per NUMA node.
28 auto pool = std::pmr::unsynchronized_pool_resource(&resource);
29
30 // Now we can use the `pool` with e.g. STL containers that use
31 // `std::pmr::polymorphic_allocator`
32 [[maybe_unused]] auto vector = std::pmr::vector<std::uint8_t>(1024, &pool);
33 [[maybe_unused]] auto string = std::pmr::string(1024, 'a', &pool);
34}
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:361
Contains memory function declarations.