3 * $Id: arena.c,v 1.1 2000/06/17 10:37:53 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.1 2000/06/17 10:37:53 mdw
34 * Basic arena management.
38 /*----- Header files ------------------------------------------------------*/
44 /*----- The standard arena ------------------------------------------------*/
46 static void *_alloc(arena
*a
, size_t sz
) { return malloc(sz
); }
47 static void *_realloc(arena
*a
, void *p
, size_t sz
){ return realloc(p
, sz
); }
48 static void _free(arena
*a
, void *p
) { free (p
); }
50 static arena_ops stdlib_ops
= { _alloc
, _realloc
, _free
, 0 };
51 arena arena_stdlib
= { &stdlib_ops
};
53 /*----- Global variables --------------------------------------------------*/
55 arena
*arena_global
= &arena_stdlib
;
57 /*----- Main code ---------------------------------------------------------*/
59 /* --- @arena_fakerealloc@ --- *
61 * Arguments: @arena *a@ = pointer to arena block
62 * @void *p@ = pointer to memory block to resize
63 * @size_t sz@ = size desired for the block
67 * Use: Standard fake @realloc@ function, for use if you don't
68 * support @realloc@ properly.
71 void *arena_fakerealloc(arena
*a
, void *p
, size_t sz
)
73 void *q
= A_ALLOC(a
, sz
);
81 /* --- Function equivalents of the macros --- */
83 void *a_alloc(arena
*a
, size_t sz
) { return (A_ALLOC(a
, sz
)); }
84 void *a_realloc(arena
*a
, void *p
, size_t sz
) { return A_REALLOC(a
, p
, sz
); }
85 void a_free(arena
*a
, void *p
) { A_FREE(a
, p
); }
87 /*----- That's all, folks -------------------------------------------------*/