3 * Abstraction for memory allocation arenas
5 * (c) 2000 Straylight/Edgeware
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of the mLib utilities library.
12 * mLib 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 * mLib 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 mLib; if not, write to the Free
24 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
28 /*----- Header files ------------------------------------------------------*/
35 /*----- The standard arena ------------------------------------------------*/
37 static void *_alloc(arena *a, size_t sz) { return malloc(sz); }
38 static void *_realloc(arena *a, void *p, size_t sz, size_t osz)
39 { return realloc(p, sz); }
40 static void _free(arena *a, void *p) { free(p); }
42 static arena_ops stdlib_ops = { _alloc, _realloc, _free, 0 };
43 arena arena_stdlib = { &stdlib_ops };
45 /*----- Global variables --------------------------------------------------*/
47 arena *arena_global = &arena_stdlib;
49 /*----- Main code ---------------------------------------------------------*/
51 /* --- @arena_fakerealloc@ --- *
53 * Arguments: @arena *a@ = pointer to arena block
54 * @void *p@ = pointer to memory block to resize
55 * @size_t sz@ = size desired for the block
56 * @size_t osz@ = size of the old block
60 * Use: Standard fake @realloc@ function, for use if you don't
61 * support @realloc@ properly.
64 void *arena_fakerealloc(arena *a, void *p, size_t sz, size_t osz)
66 void *q = A_ALLOC(a, sz);
69 memcpy(q, p, sz > osz ? osz : sz);
74 /* --- Function equivalents of the macros --- */
76 void *a_alloc(arena *a, size_t sz) { return (A_ALLOC(a, sz)); }
77 void *a_realloc(arena *a, void *p, size_t sz, size_t osz)
78 { return A_REALLOC(a, p, sz, osz); }
79 void a_free(arena *a, void *p) { A_FREE(a, p); }
81 /*----- That's all, folks -------------------------------------------------*/