aboutsummaryrefslogtreecommitdiff
path: root/include/scoped_allocator.h
blob: 1193439fb5a4a153495c0259ec2715852b5d5b40 (plain)
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
#ifndef AMALGAM_SCOPED_ALLOCATOR_H
#define AMALGAM_SCOPED_ALLOCATOR_H

#include "misc.h"
#include "types.h"

typedef struct ScopedAllocatorNode ScopedAllocatorNode;

struct ScopedAllocatorNode {
    char *data;
    usize size;
    ScopedAllocatorNode *next;
};

typedef struct {
    ScopedAllocatorNode head;
    ScopedAllocatorNode *current;
} ScopedAllocator;

CHECK_RESULT int scoped_allocator_node_init(ScopedAllocatorNode *self);
void scoped_allocator_node_deinit(ScopedAllocatorNode *self);

CHECK_RESULT int scoped_allocator_init(ScopedAllocator *self);
void scoped_allocator_deinit(ScopedAllocator *self);
CHECK_RESULT int scoped_allocator_alloc(ScopedAllocator *self, usize size, void **mem);

#endif