3 * $Id: mparena.h,v 1.4 2004/04/08 01:36:15 mdw Exp $
5 * Allocation and freeing of MP buffers
7 * (c) 1999 Straylight/Edgeware
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of Catacomb.
14 * Catacomb 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.
19 * Catacomb 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.
24 * You should have received a copy of the GNU Library General Public
25 * License along with Catacomb; if not, write to the Free
26 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
30 #ifndef CATACOMB_MPARENA_H
31 #define CATACOMB_MPARENA_H
37 /*----- Header files ------------------------------------------------------*/
39 #include <mLib/arena.h>
41 #ifndef CATACOMB_MPW_H
45 /*----- Data structures ---------------------------------------------------*/
47 /* --- @mparena_node@ --- *
49 * For internal use by the MP arena manager. The free blocks are held in a
50 * binary tree by size, held in the first digit of each vector.
53 typedef struct mparena_node {
54 struct mparena_node *left, *right;
58 /* --- @mparena@ --- *
63 typedef struct mparena {
69 /*----- Standard arenas ---------------------------------------------------*/
71 extern mparena mparena_global;
72 #define MPARENA_GLOBAL (&mparena_global)
74 extern mparena mparena_secure;
75 #define MPARENA_SECURE (&mparena_secure)
77 /*----- Functions provided ------------------------------------------------*/
79 /* --- @mparena_create@ --- *
81 * Arguments: @mparena *a@ = pointer to arena block
85 * Use: Initializes an MP arena so that blocks can be allocated from
89 extern void mparena_create(mparena */*a*/);
91 #define MPARENA_INIT { 0, 0, &arena_stdlib }
93 /* --- @mparena_setarena@ --- *
95 * Arguments: @mparena *a@ = pointer to MP arena block
96 * @arena *aa@ = pointer to arena
100 * Use: Sets the underlying arena for an MP arena.
103 extern void mparena_setarena(mparena */*a*/, arena */*aa*/);
105 /* --- @mparena_destroy@ --- *
107 * Arguments: @mparena *a@ = pointer to arena block
111 * Use: Frees an MP arena, and all the vectors held within it. The
112 * blocks which are currently allocated can be freed into some
113 * other MP arena, as long as the underlying arenas are the
117 extern void mparena_destroy(mparena */*a*/);
119 /* --- @mparena_count@ --- *
121 * Arguments: @mparena *a@ = pointer to arena block
123 * Returns: Number of allocated blocks from this arena.
125 * Use: Reports the number of blocks allocated from the arena and not
129 extern unsigned mparena_count(mparena */*a*/);
131 /* --- @mpalloc@ --- *
133 * Arguments: @mparena *a@ = pointer to arena block
134 * @size_t sz@ = number of digits required
136 * Returns: Pointer to a suitably sized block.
138 * Use: Allocates a lump of data suitable for use as an array of MP
142 extern mpw *mpalloc(mparena */*a*/, size_t /*sz*/);
144 /* --- @mpfree@ --- *
146 * Arguments: @mparena *a@ = pointer to arena block
147 * @mpw *v@ = pointer to allocated vector
151 * Use: Returns an MP vector to an arena.
154 extern void mpfree(mparena */*a*/, mpw */*v*/);
156 /*----- That's all, folks -------------------------------------------------*/