-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathblock.h
40 lines (30 loc) · 997 Bytes
/
block.h
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
#ifndef INTERN_BLOCK_H_
#define INTERN_BLOCK_H_
#include <stddef.h>
#include <stdbool.h>
struct block {
size_t page_size;
void **pages;
size_t *offsets;
size_t count;
size_t size;
};
// Create a new block allocator
struct block *block_new(size_t page_size);
// Free a block allocator
void block_free(struct block*);
// Allocate a chunk of bytes
void *block_alloc(struct block*, size_t bytes);
struct block_snapshot {
size_t count;
size_t offset;
};
// Create a snapshot. The block can later be restored to this position
void block_snapshot(const struct block*, struct block_snapshot*);
// Restore the allocator to a previous position. Any allocations made after
// the snapshot are removed. This function returns true if the restore was
// successful, and false if an error occurred
bool block_restore(struct block*, const struct block_snapshot*);
// Get the total bytes allocated, including overhead
size_t block_allocated_bytes(const struct block*);
#endif