-
Notifications
You must be signed in to change notification settings - Fork 13
/
c_api.c
69 lines (50 loc) · 1.52 KB
/
c_api.c
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// 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>
#include <metall/c_api/metall.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_free(manager, x);
metall_close(manager);
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;
metall_flush(manager);
array[1] = 1;
metall_snapshot(manager, "/tmp/metall2-snap");
metall_close(manager);
}
// 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_named_free(manager, "array");
metall_close(manager);
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_named_free(manager, "array");
metall_close(manager);
metall_remove("/tmp/metall2-snap");
}
return 0;
}