diff options
Diffstat (limited to 'include/slab.h')
-rw-r--r-- | include/slab.h | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/include/slab.h b/include/slab.h new file mode 100644 index 0000000..04d42e4 --- /dev/null +++ b/include/slab.h @@ -0,0 +1,44 @@ +#ifndef JOVE_MEMORY_SLAB_H +#define JOVE_MEMORY_SLAB_H 1 + +#include <stdint.h> +#include <stddef.h> +#include <stdbool.h> + +#define SLABCACHE_NAME_LIMIT 32 +typedef struct slab_cache +{ + char name[SLABCACHE_NAME_LIMIT]; + + struct slab *list_free; + struct slab *list_partial; + struct slab *list_full; + + size_t obj_count; + size_t obj_size; + size_t obj_capacity; + + size_t slab_pages; +} slab_cache_t; + +typedef struct slab +{ + struct slab *prev; + struct slab *next; + void *slab_base; + void *obj_base; + + size_t free_count; + int free_index; + uintptr_t free[]; +} slab_t; + +void slabcache_new(slab_cache_t *cache, char *name, size_t objsize); + +void* slab_alloc(slab_cache_t *cache); +void slab_free(slab_cache_t *cache, void *ptr); + +void* slab_get(slab_cache_t *cache, size_t index); +void slab_set(slab_cache_t *cache, size_t index, void *data); + +#endif |