3 * Allocation and freeing of MP buffers
5 * (c) 1999 Straylight/Edgeware
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of Catacomb.
12 * Catacomb is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Library General Public License as
14 * published by the Free Software Foundation; either version 2 of the
15 * License, or (at your option) any later version.
17 * Catacomb is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Library General Public License for more details.
22 * You should have received a copy of the GNU Library General Public
23 * License along with Catacomb; if not, write to the Free
24 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
28 #ifndef CATACOMB_MPARENA_H
29 #define CATACOMB_MPARENA_H
35 /*----- Header files ------------------------------------------------------*/
37 #include <mLib/arena.h>
39 #ifndef CATACOMB_MPW_H
43 /*----- Data structures ---------------------------------------------------*/
45 /* --- @mparena_node@ --- *
47 * For internal use by the MP arena manager. The free blocks are held in a
48 * binary tree by size, held in the first digit of each vector.
51 typedef struct mparena_node {
52 struct mparena_node *left, *right;
56 /* --- @mparena@ --- *
61 typedef struct mparena {
67 /*----- Standard arenas ---------------------------------------------------*/
69 extern mparena mparena_global;
70 #define MPARENA_GLOBAL (&mparena_global)
72 extern mparena mparena_secure;
73 #define MPARENA_SECURE (&mparena_secure)
75 /*----- Functions provided ------------------------------------------------*/
77 /* --- @mparena_create@ --- *
79 * Arguments: @mparena *a@ = pointer to arena block
83 * Use: Initializes an MP arena so that blocks can be allocated from
87 extern void mparena_create(mparena */*a*/);
89 #define MPARENA_INIT { 0, 0, &arena_stdlib }
91 /* --- @mparena_setarena@ --- *
93 * Arguments: @mparena *a@ = pointer to MP arena block
94 * @arena *aa@ = pointer to arena
98 * Use: Sets the underlying arena for an MP arena.
101 extern void mparena_setarena(mparena */*a*/, arena */*aa*/);
103 /* --- @mparena_destroy@ --- *
105 * Arguments: @mparena *a@ = pointer to arena block
109 * Use: Frees an MP arena, and all the vectors held within it. The
110 * blocks which are currently allocated can be freed into some
111 * other MP arena, as long as the underlying arenas are the
115 extern void mparena_destroy(mparena */*a*/);
117 /* --- @mparena_count@ --- *
119 * Arguments: @mparena *a@ = pointer to arena block
121 * Returns: Number of allocated blocks from this arena.
123 * Use: Reports the number of blocks allocated from the arena and not
127 extern unsigned mparena_count(mparena */*a*/);
129 /* --- @mpalloc@ --- *
131 * Arguments: @mparena *a@ = pointer to arena block
132 * @size_t sz@ = number of digits required
134 * Returns: Pointer to a suitably sized block.
136 * Use: Allocates a lump of data suitable for use as an array of MP
140 extern mpw *mpalloc(mparena */*a*/, size_t /*sz*/);
142 /* --- @mpfree@ --- *
144 * Arguments: @mparena *a@ = pointer to arena block
145 * @mpw *v@ = pointer to allocated vector
149 * Use: Returns an MP vector to an arena.
152 extern void mpfree(mparena */*a*/, mpw */*v*/);
154 /*----- That's all, folks -------------------------------------------------*/