Metall  v0.27
A persistent memory allocator for data-centric analytics
c_api.c

This is an example of how to use the C API.

// Copyright 2019 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 <assert.h>
int main(void) {
// Basic allocation
{
metall_open(METALL_CREATE_ONLY, "/tmp/metall1");
uint64_t *x = metall_malloc(sizeof(uint64_t));
x[0] = 1;
}
// Allocate named object
{
metall_open(METALL_CREATE_ONLY, "/tmp/metall2");
uint64_t *array = metall_named_malloc("array", sizeof(uint64_t) * 10);
array[0] = 0;
array[1] = 1;
}
// Retrieve named object
{
metall_open(METALL_OPEN_ONLY, "/tmp/metall2");
uint64_t *array = metall_find("array");
assert(array[0] == 0);
assert(array[1] == 1);
}
return 0;
}
int main()
Definition: jgraph.cpp:24
void * metall_malloc(uint64_t nbytes)
Allocates nbytes bytes.
void metall_close()
Destructs Metall manager object.
void * metall_find(char *name)
Finds a saved memory.
void metall_named_free(const char *name)
Frees memory with the name.
void * metall_named_malloc(const char *name, uint64_t nbytes)
Allocates nbytes bytes and save the address of the allocated memory with name.
int metall_open(int mode, const char *path)
Constructs a Metall manager object.
#define METALL_OPEN_ONLY
Tag to open an already created segment.
Definition: metall.h:20
#define METALL_CREATE_ONLY
Tag to create the segment always. The existing segment with the same name is over written.
Definition: metall.h:17
void metall_free(void *ptr)
Frees the allocated memory.
void metall_flush()
Flush data to persistent memory.