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