about summary refs log blame commit diff stats
path: root/cached.h
blob: 454bcc3020e8bc245464a177357c03d383d7ed18 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11




                 





                                                                             
   
                                           
 



                              


               


                                                   


                      


                                                         



                 
#pragma once

#ifndef CACHED_H_
#define CACHED_H_

#include <stddef.h>

/**
 * Create cache of size `slots` for allocating chunks of `object_size` bytes.
 * Return 0 on success, <0 on failure.
 */
int
ca_setup(size_t object_size, size_t slots);

/**
 * Allocate a chunk of memory.
 * Return NULL on failure.
 */
void *
ca_alloc(void);

/**
 * Free a chunk of memory obtained from `ca_alloc`.
 */
void
ca_free(void *object);

/**
 * Destroy the cache, freeing all memory still allocated.
 */
void
ca_cleanup(void);

#endif