From 314a53cd63f1f28cf5e95eb612181cfffc152135 Mon Sep 17 00:00:00 2001 From: James Bursa Date: Fri, 2 Jan 2004 12:04:29 +0000 Subject: [project @ 2004-01-02 12:04:29 by bursa] Implement memory pools. svn path=/import/netsurf/; revision=478 --- utils/pool.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 utils/pool.h (limited to 'utils/pool.h') diff --git a/utils/pool.h b/utils/pool.h new file mode 100644 index 000000000..4dceb3f47 --- /dev/null +++ b/utils/pool.h @@ -0,0 +1,38 @@ +/* + * This file is part of NetSurf, http://netsurf.sourceforge.net/ + * Licensed under the GNU General Public License, + * http://www.opensource.org/licenses/gpl-license + * Copyright 2003 James Bursa + */ + +/** \file + * Memory pool manager (interface). + * + * A memory pool is intended for allocating memory which is required in small + * blocks and all released together. It avoids the overhead of many small + * malloc()s. + * + * Create a pool using pool_create(), and allocate memory from it using + * pool_alloc() and pool_string(). Destroy and free the entire pool using + * pool_destroy(). + * + * The suggested block size should be large enough to store many allocations. + * Use a multiple of the size of contents, if fixed. Larger allocations than + * the block size are possible. + */ + +#ifndef _NETSURF_UTILS_POOL_H_ +#define _NETSURF_UTILS_POOL_H_ + +#include + +/** Opaque memory pool handle. */ +typedef struct pool *pool; + +pool pool_create(size_t block_size); +void pool_destroy(pool p); +void *pool_alloc(pool p, size_t size); +char *pool_string(pool p, const char *s); + +#endif + -- cgit v1.2.3