lsquic_malo.h revision 06b2a236
1/* Copyright (c) 2017 - 2021 LiteSpeed Technologies Inc. See LICENSE. */ 2/* 3 * lsquic_malo.h -- Fast allocator for fixed-sized objects. 4 */ 5 6#ifndef LSQUIC_MALO_H 7#define LSQUIC_MALO_H 1 8 9#ifndef LSQUIC_USE_POOLS 10#define LSQUIC_USE_POOLS 1 11#endif 12 13struct malo; 14 15/* Create a malo allocator for objects of size `obj_size'. */ 16struct malo * 17lsquic_malo_create (size_t obj_size); 18 19/* Get a new object. */ 20void * 21lsquic_malo_get (struct malo *); 22 23/* Return obj to the pool */ 24void 25lsquic_malo_put (void *obj); 26 27/* This deallocates all remaining objects. */ 28void 29lsquic_malo_destroy (struct malo *); 30 31/* This iterator is slow. It is only used in unit tests for verification. 32 * 33 * If you to iterate over all elements allocated in a pool, keep track yourself. 34 */ 35/* The iterator is built-in. Usage: 36 * void *obj; 37 * for (obj = lsquic_malo_first(obj); obj; lsquic_malo_next(obj)) 38 * do_stuff(obj); 39 */ 40void * 41lsquic_malo_first (struct malo *); 42 43void * 44lsquic_malo_next (struct malo *); 45 46size_t 47lsquic_malo_mem_used (const struct malo *); 48 49#endif 50