3 * $Id: arena.c,v 1.2 2000/07/16 12:29:16 mdw Exp $
5 * Abstraction for memory allocation arenas
7 * (c) 2000 Straylight/Edgeware
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of the mLib utilities library.
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.
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.
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,
30 /*----- Revision history --------------------------------------------------*
33 * Revision 1.2 2000/07/16 12:29:16 mdw
34 * Change to arena `realloc' interface, to fix a design bug.
36 * Revision 1.1 2000/06/17 10:37:53 mdw
37 * Basic arena management.
41 /*----- Header files ------------------------------------------------------*/
47 /*----- The standard arena ------------------------------------------------*/
49 static void *_alloc(arena
*a
, size_t sz
) { return malloc(sz
); }
50 static void *_realloc(arena
*a
, void *p
, size_t sz
, size_t osz
)
51 { return realloc(p
, sz
); }
52 static void _free(arena
*a
, void *p
) { free (p
); }
54 static arena_ops stdlib_ops
= { _alloc
, _realloc
, _free
, 0 };
55 arena arena_stdlib
= { &stdlib_ops
};
57 /*----- Global variables --------------------------------------------------*/
59 arena
*arena_global
= &arena_stdlib
;
61 /*----- Main code ---------------------------------------------------------*/
63 /* --- @arena_fakerealloc@ --- *
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
72 * Use: Standard fake @realloc@ function, for use if you don't
73 * support @realloc@ properly.
76 void *arena_fakerealloc(arena
*a
, void *p
, size_t sz
, size_t osz
)
78 void *q
= A_ALLOC(a
, sz
);
81 memcpy(q
, p
, sz
> osz ? osz
: sz
);
86 /* --- Function equivalents of the macros --- */
88 void *a_alloc(arena
*a
, size_t sz
) { return (A_ALLOC(a
, sz
)); }
89 void *a_realloc(arena
*a
, void *p
, size_t sz
, size_t osz
)
90 { return A_REALLOC(a
, p
, sz
, osz
); }
91 void a_free(arena
*a
, void *p
) { A_FREE(a
, p
); }
93 /*----- That's all, folks -------------------------------------------------*/