libcute 0.1
Loading...
Searching...
No Matches
allocator.h
Go to the documentation of this file.
1#pragma once
2
5#include <stddef.h>
6
7#include "io/error.h"
8#include "nostd.h"
9#include "utility.h"
10
12typedef cu_IoSlice_Result (*cu_Allocator_AllocFunc)(
13 void *self, cu_Layout layout);
15typedef cu_IoSlice_Result (*cu_Allocator_GrowFunc)(
16 void *self, cu_Slice old_mem, cu_Layout new_layout);
18typedef cu_IoSlice_Result (*cu_Allocator_ShrinkFunc)(
19 void *self, cu_Slice old_mem, cu_Layout new_layout);
21typedef void (*cu_Allocator_FreeFunc)(void *self, cu_Slice mem);
22
32
33
34static inline cu_IoSlice_Result cu_Allocator_Alloc(
35 cu_Allocator allocator, cu_Layout layout) {
36 return allocator.allocFn(allocator.self, layout);
37}
38
40static inline cu_IoSlice_Result cu_Allocator_Grow(
41 cu_Allocator allocator, cu_Slice old_mem, cu_Layout new_layout) {
42 return allocator.growFn(allocator.self, old_mem, new_layout);
43}
44
46static inline cu_IoSlice_Result cu_Allocator_Shrink(
47 cu_Allocator allocator, cu_Slice old_mem, cu_Layout new_layout) {
48 return allocator.shrinkFn(allocator.self, old_mem, new_layout);
49}
50
52static inline void cu_Allocator_Free(cu_Allocator allocator, cu_Slice mem) {
53 allocator.freeFn(allocator.self, mem);
54}
55
57#if !CU_FREESTANDING
59#endif
60
cu_IoSlice_Result(* cu_Allocator_GrowFunc)(void *self, cu_Slice old_mem, cu_Layout new_layout)
Definition allocator.h:15
cu_Allocator cu_Allocator_CAllocator(void)
Definition allocator.c:130
cu_Allocator cu_Allocator_NullAllocator(void)
Definition allocator.c:178
cu_IoSlice_Result(* cu_Allocator_ShrinkFunc)(void *self, cu_Slice old_mem, cu_Layout new_layout)
Definition allocator.h:18
void(* cu_Allocator_FreeFunc)(void *self, cu_Slice mem)
Definition allocator.h:21
cu_IoSlice_Result(* cu_Allocator_AllocFunc)(void *self, cu_Layout layout)
Definition allocator.h:12
#define CU_OPTIONAL_DECL(NAME, T)
Definition optional.h:25
Definition allocator.h:24
cu_Allocator_FreeFunc freeFn
Definition allocator.h:29
cu_Allocator_ShrinkFunc shrinkFn
Definition allocator.h:28
void * self
Definition allocator.h:25
cu_Allocator_AllocFunc allocFn
Definition allocator.h:26
cu_Allocator_GrowFunc growFn
Definition allocator.h:27
Definition utility.h:22
Definition nostd.h:27