Metall  v0.29
A persistent memory allocator for data-centric analytics
fallback_allocator.cpp

This is an example of how to use fallback_allocator.

// 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>
using vector_t =
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;
}
A generalized Metall manager class.
Definition: basic_manager.hpp:40
int main()
Definition: jgraph.cpp:24
boost::container::vector< T, Allocator > vector
A vector container that uses Metall as its default allocator.
Definition: vector.hpp:17
basic_manager<> manager
Default Metall manager class which is an alias of basic_manager with the default template parameters.
Definition: metall.hpp:34