3 * $Id: mparena.h,v 1.1 1999/11/17 18:02:16 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.1 1999/11/17 18:02:16 mdw
34 * New multiprecision integer arithmetic suite.
45 /*----- Header files ------------------------------------------------------*/
51 /*----- Data structures ---------------------------------------------------*/
53 /* --- @mparena_node@ --- *
55 * For internal use by the MP arena manager. The free blocks are held in a
56 * binary tree by size, held in the first digit of each vector.
59 typedef struct mparena_node
{
60 struct mparena_node
*left
, *right
;
64 /* --- @mparena@ --- *
69 typedef struct mparena
{
71 struct mparena_ops
*ops
;
74 /* --- @mparena_ops@ --- *
76 * Operations required for an arena memory manager. The default manager just
77 * calls @xmalloc@ and @free@, although it's possible to envisage a more
78 * paranoid implementation which allocates locked memory pages. Switch them
79 * over with @mparena_setops@. It's usual to only do this when you've
80 * attached your extra state to the end of the @mparena@ structure.
83 typedef struct mparena_ops
{
84 void *(*alloc
)(mparena */
*a*/
, size_t /*sz*/);
85 void (*free
)(mparena */
*a*/
, void */
*p*/
);
88 /*----- Magical constants -------------------------------------------------*/
90 #define MPARENA_GLOBAL ((mparena *)0)
92 extern mparena_ops mparena_defaultops
;
94 /*----- Functions provided ------------------------------------------------*/
96 /* --- @mparena_create@ --- *
98 * Arguments: @mparena *a@ = pointer to arena block
102 * Use: Initializes an MP arena so that blocks can be allocated from
106 extern void mparena_create(mparena */
*a*/
);
108 #define MPARENA_INIT { 0, &mparena_defaultops }
110 /* --- @mparena_setops@ --- *
112 * Arguments: @mparena *a@ = pointer to arena block
113 * @mparena_ops *ops@ = pointer to operations block or null
115 * Returns: The previous operations block.
117 * Use: Sets or queries the operations attached to an arena.
120 extern mparena_ops
*mparena_setops(mparena */
*a*/
, mparena_ops */
*ops*/
);
122 /* --- @mparena_destroy@ --- *
124 * Arguments: @mparena *a@ = pointer to arena block
128 * Use: Frees an MP arena, and all the vectors held within it. The
129 * blocks which are currently allocated can be freed into some
133 extern void mparena_destroy(mparena */
*a*/
);
135 /* --- @mpalloc@ --- *
137 * Arguments: @mparena *a@ = pointer to arena block
138 * @size_t sz@ = number of digits required
140 * Returns: Pointer to a suitably sized block.
142 * Use: Allocates a lump of data suitable for use as an array of MP
146 extern mpw
*mpalloc(mparena */
*a*/
, size_t /*sz*/);
148 /* --- @mpfree@ --- *
150 * Arguments: @mparena *a@ = pointer to arena block
151 * @mpw *v@ = pointer to allocated vector
155 * Use: Returns an MP vector to an arena. It doesn't have to be
156 * returned to the arena from which it was allocated.
159 extern void mpfree(mparena */
*a*/
, mpw */
*v*/
);
161 /*----- That's all, folks -------------------------------------------------*/