sla.h
Go to the documentation of this file.
1 #pragma once
2 
7 
18 
19 #include <inttypes.h>
20 #include <stdbool.h>
21 
22 typedef struct{
26  void **slabs;
29  void *first_elem;
31  uint64_t slabs_len;
33  uint64_t slab_cap;
35  uint64_t elem_size;
36 } cr8r_sla;
37 
44 bool cr8r_sla_init(cr8r_sla *self, uint64_t elem_size, uint64_t cap);
45 
51 
58 void *cr8r_sla_alloc(cr8r_sla *self);
59 
70 void cr8r_sla_free(cr8r_sla *self, void *p);
71 
void * cr8r_sla_alloc(cr8r_sla *self)
Allocate an object.
void cr8r_sla_free(cr8r_sla *self, void *p)
Frees and object which was previously allocated by cr8r_sla_alloc.
void cr8r_sla_delete(cr8r_sla *self)
Delete a slab allocator.
bool cr8r_sla_init(cr8r_sla *self, uint64_t elem_size, uint64_t cap)
Initialize a slab allocator.
Slab allocator.
Definition: sla.h:22
uint64_t slabs_len
Number of slabs.
Definition: sla.h:31
uint64_t elem_size
Size of a single element.
Definition: sla.h:35
uint64_t slab_cap
Capacity of last slab.
Definition: sla.h:33
void ** slabs
Array of pointers to "slabs" (elements buffers).
Definition: sla.h:26
void * first_elem
Pointer to first unallocated element.
Definition: sla.h:29