3 * $Id: mparena.h,v 1.2 1999/12/10 23:28:59 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 /*----- Revision history --------------------------------------------------*
33 * Revision 1.2 1999/12/10 23:28:59 mdw
34 * Memory allocation counting.
36 * Revision 1.1 1999/11/17 18:02:16 mdw
37 * New multiprecision integer arithmetic suite.
41 #ifndef CATACOMB_MPARENA_H
42 #define CATACOMB_MPARENA_H
48 /*----- Header files ------------------------------------------------------*/
50 #ifndef CATACOMB_MPW_H
54 /*----- Data structures ---------------------------------------------------*/
56 /* --- @mparena_node@ --- *
58 * For internal use by the MP arena manager. The free blocks are held in a
59 * binary tree by size, held in the first digit of each vector.
62 typedef struct mparena_node
{
63 struct mparena_node
*left
, *right
;
67 /* --- @mparena@ --- *
72 typedef struct mparena
{
75 struct mparena_ops
*ops
;
78 /* --- @mparena_ops@ --- *
80 * Operations required for an arena memory manager. The default manager just
81 * calls @xmalloc@ and @free@, although it's possible to envisage a more
82 * paranoid implementation which allocates locked memory pages. Switch them
83 * over with @mparena_setops@. It's usual to only do this when you've
84 * attached your extra state to the end of the @mparena@ structure.
87 typedef struct mparena_ops
{
88 void *(*alloc
)(mparena */
*a*/
, size_t /*sz*/);
89 void (*free
)(mparena */
*a*/
, void */
*p*/
);
92 /*----- Magical constants -------------------------------------------------*/
94 #define MPARENA_GLOBAL ((mparena *)0)
96 extern mparena_ops mparena_defaultops
;
98 /*----- Functions provided ------------------------------------------------*/
100 /* --- @mparena_create@ --- *
102 * Arguments: @mparena *a@ = pointer to arena block
106 * Use: Initializes an MP arena so that blocks can be allocated from
110 extern void mparena_create(mparena */
*a*/
);
112 #define MPARENA_INIT { 0, 0, &mparena_defaultops }
114 /* --- @mparena_setops@ --- *
116 * Arguments: @mparena *a@ = pointer to arena block
117 * @mparena_ops *ops@ = pointer to operations block or null
119 * Returns: The previous operations block.
121 * Use: Sets or queries the operations attached to an arena.
124 extern mparena_ops
*mparena_setops(mparena */
*a*/
, mparena_ops */
*ops*/
);
126 /* --- @mparena_destroy@ --- *
128 * Arguments: @mparena *a@ = pointer to arena block
132 * Use: Frees an MP arena, and all the vectors held within it. The
133 * blocks which are currently allocated can be freed into some
137 extern void mparena_destroy(mparena */
*a*/
);
139 /* --- @mparena_count@ --- *
141 * Arguments: @mparena *a@ = pointer to arena block
143 * Returns: Number of allocated blocks from this arena.
145 * Use: Reports the number of blocks allocated from the arena and not
149 extern unsigned mparena_count(mparena */
*a*/
);
151 /* --- @mpalloc@ --- *
153 * Arguments: @mparena *a@ = pointer to arena block
154 * @size_t sz@ = number of digits required
156 * Returns: Pointer to a suitably sized block.
158 * Use: Allocates a lump of data suitable for use as an array of MP
162 extern mpw
*mpalloc(mparena */
*a*/
, size_t /*sz*/);
164 /* --- @mpfree@ --- *
166 * Arguments: @mparena *a@ = pointer to arena block
167 * @mpw *v@ = pointer to allocated vector
171 * Use: Returns an MP vector to an arena.
174 extern void mpfree(mparena */
*a*/
, mpw */
*v*/
);
176 /*----- That's all, folks -------------------------------------------------*/