-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathfallback_allocator.cpp
More file actions
33 lines (27 loc) · 1010 Bytes
/
fallback_allocator.cpp
File metadata and controls
33 lines (27 loc) · 1010 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Copyright 2020 Lawrence Livermore National Security, LLC and other Metall
// Project Developers. See the top-level COPYRIGHT file for details.
//
// SPDX-License-Identifier: (Apache-2.0 OR MIT)
#include <iostream>
#include <metall/metall.hpp>
#include <metall/container/vector.hpp>
using vector_t =
metall::container::vector<int, metall::manager::fallback_allocator<int>>;
int main() {
// Allocation using Metall
{
metall::manager manager(metall::create_only, "/tmp/dir");
auto pvec = manager.construct<vector_t>("vec")(manager.get_allocator());
pvec->push_back(1);
std::cout << (*pvec)[0] << std::endl;
}
// Allocation not using Metall, i.e., uses a heap allocator (malloc()).
// This code would cause a build error if fallback_allocator were not used.
{
vector_t vec; // As no metall allocator argument is passed, the fallback
// allocator uses malloc() internally.
vec.push_back(2);
std::cout << vec[0] << std::endl;
}
return 0;
}