Missing argument in sel_addtimer docs.
[mLib] / arena.h
1 /* -*-c-*-
2 *
3 * $Id$
4 *
5 * Abstraction for memory allocation arenas
6 *
7 * (c) 2000 Straylight/Edgeware
8 */
9
10 /*----- Licensing notice --------------------------------------------------*
11 *
12 * This file is part of the mLib utilities library.
13 *
14 * mLib is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU Library General Public License as
16 * published by the Free Software Foundation; either version 2 of the
17 * License, or (at your option) any later version.
18 *
19 * mLib is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Library General Public License for more details.
23 *
24 * You should have received a copy of the GNU Library General Public
25 * License along with mLib; if not, write to the Free
26 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
27 * MA 02111-1307, USA.
28 */
29
30 #ifndef MLIB_ARENA_H
31 #define MLIB_ARENA_H
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 /*----- Header files ------------------------------------------------------*/
38
39 #include <stdlib.h>
40
41 /*----- Data structures ---------------------------------------------------*/
42
43 /* --- An arena structure --- */
44
45 typedef struct arena {
46 const struct arena_ops *ops;
47 } arena;
48
49 typedef struct arena_ops {
50 void *(*alloc)(arena */*a*/, size_t /*sz*/);
51 void *(*realloc)(arena */*a*/, void */*p*/, size_t /*sz*/, size_t /*osz*/);
52 void (*free)(arena */*a*/, void */*p*/);
53 void (*purge)(arena */*a*/);
54 } arena_ops;
55
56 /*----- Global variables --------------------------------------------------*/
57
58 extern arena *arena_global; /* Standard global arena */
59 extern arena arena_stdlib; /* Arena based on @malloc@/@free@ */
60
61 /*----- Functions provided ------------------------------------------------*/
62
63 /* --- @arena_fakerealloc@ --- *
64 *
65 * Arguments: @arena *a@ = pointer to arena block
66 * @void *p@ = pointer to memory block to resize
67 * @size_t sz@ = size desired for the block
68 * @size_t osz@ = size of the old block
69 *
70 * Returns: ---
71 *
72 * Use: Standard fake @realloc@ function, for use if you don't
73 * support @realloc@ properly.
74 */
75
76 extern void *arena_fakerealloc(arena */*a*/, void */*p*/,
77 size_t /*sz*/, size_t /*osz*/);
78
79 /* --- Useful macros --- */
80
81 #define A_ALLOC(a, sz) (((a)->ops->alloc)((a), (sz)))
82 #define A_REALLOC(a, p, sz, osz) (((a)->ops->realloc)((a), (p), (sz), (osz)))
83 #define A_FREE(a, p) (((a)->ops->free)((a), (p)))
84
85 /* --- Simple function equivalents --- */
86
87 extern void *a_alloc(arena */*a*/, size_t /*sz*/);
88 extern void *a_realloc(arena */*a*/, void */*p*/,
89 size_t /*sz*/, size_t /*osz*/);
90 extern void a_free(arena */*a*/, void */*p*/);
91
92 /*----- That's all, folks -------------------------------------------------*/
93
94 #ifdef __cplusplus
95 }
96 #endif
97
98 #endif