Metall  v0.28
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>
#include <stdint.h>
int main(void) {
// Basic allocation
{
metall_manager* manager = metall_create("/tmp/metall1");
uint64_t* x = metall_malloc(manager, sizeof(uint64_t));
x[0] = 1;
metall_remove("/tmp/metall1");
}
// Allocate named object
{
metall_manager* manager = metall_create("/tmp/metall2");
uint64_t* array = metall_named_malloc(manager, "array",
sizeof(uint64_t) * 10);
array[0] = 0;
array[1] = 1;
metall_snapshot(manager, "/tmp/metall2-snap");
}
// Retrieve named object
{
metall_manager* manager = metall_open("/tmp/metall2");
uint64_t* array = metall_find(manager, "array");
assert(array[0] == 0);
assert(array[1] == 1);
metall_remove("/tmp/metall2");
}
// Retrieve object snapshot
{
metall_manager* manager = metall_open("/tmp/metall2-snap");
uint64_t* array = metall_find(manager, "array");
assert(array[0] == 0);
assert(array[1] == 1);
metall_remove("/tmp/metall2-snap");
}
return 0;
}
int main()
Definition: jgraph.cpp:24
void metall_close(metall_manager *manager)
Closes a metall manager.
bool metall_snapshot(metall_manager *manager, const char *dst_path)
Creates a snapshot of the metall datastore of manager and places it at dst_path.
struct metall_manager metall_manager
Opaque struct representing a metall manager.
Definition: metall.h:21
void * metall_named_malloc(metall_manager *manager, const char *name, size_t size)
Allocates size bytes and associates the allocated memory with a name.
void metall_free(metall_manager *manager, void *ptr)
Frees memory previously allocated by metall_malloc.
bool metall_remove(const char *path)
Removes the metall datastore at path.
metall_manager * metall_open(const char *path)
Attempts to open the metall datastore at path.
metall_manager * metall_create(const char *path)
Attempts to create a metall datastore at path.
void * metall_find(metall_manager *manager, const char *name)
Finds memory that was previously allocated using metall_named_alloc.
void * metall_malloc(metall_manager *manager, size_t size)
Allocates size bytes.
bool metall_named_free(metall_manager *manager, const char *name)
Frees memory previously allocated by metall_named_malloc.
void metall_flush(metall_manager *manager)
Flushes the given manager.
basic_manager<> manager
Default Metall manager class which is an alias of basic_manager with the default template parameters.
Definition: metall.hpp:34