-
Notifications
You must be signed in to change notification settings - Fork 0
/
alloc.h
28 lines (20 loc) · 1014 Bytes
/
alloc.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
#ifndef ALLOC_H
#define ALLOC_H
#include <stdlib.h>
/* Allocator which progressively grows and is freed in one go */
struct arena_allocator;
void arena_allocator_create(struct arena_allocator **allocator);
void arena_allocator_free(struct arena_allocator **allocator);
/* Alloc word-aligned block in arena */
void *arena_alloc(struct arena_allocator *allocator, size_t size);
void *arena_alloc_init(struct arena_allocator *allocator, size_t size,
void *data);
/* Alloc space necessary for `str` (including null-terminator), then copy it
into that space. Returns the start of the new allocation */
void *arena_alloc_strcpy(struct arena_allocator *allocator, const char *str);
/* Try and expand the allocation at `ptr` to `size`.
- If `ptr` is `NULL`, acts the same as calling `arena_alloc(allocator,
size)`
- If `size` is less than the allocation size, this method does nothing */
void *arena_realloc(struct arena_allocator *allocator, void *ptr, size_t size);
#endif