3 * $Id: alloc.h,v 1.5 2000/06/17 10:35:51 mdw Exp $
5 * Memory allocation functions
7 * (c) 1998 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.5 2000/06/17 10:35:51 mdw
34 * Major overhaul for arena support.
36 * Revision 1.4 1999/12/10 23:42:04 mdw
37 * Change header file guard names.
39 * Revision 1.3 1999/05/06 19:51:35 mdw
40 * Reformatted the LGPL notice a little bit.
42 * Revision 1.2 1999/05/05 18:50:31 mdw
43 * Change licensing conditions to LGPL.
45 * Revision 1.1.1.1 1998/06/17 23:44:42 mdw
46 * Initial version of mLib
57 /*----- Required header files ---------------------------------------------*/
65 /*----- Functions and macros ----------------------------------------------*/
67 /* --- @x_alloc@ --- *
69 * Arguments: @arena *a@ = pointer to underlying arena
70 * @size_t sz@ = size of block to allocate
72 * Returns: Pointer to allocated block.
74 * Use: Allocates memory. If there's not enough memory, the
75 * exception @EXC_NOMEM@ is thrown.
78 extern void *x_alloc(arena */*a*/, size_t /*sz*/);
80 /* --- @x_strdup@ --- *
82 * Arguments: @arena *a@ = pointer to underlying arena
83 * @const char *s@ = pointer to a string
85 * Returns: Pointer to a copy of the string.
87 * Use: Copies a string (like @strdup@ would, if it existed). If
88 * there's not enough memory, the exception @EXC_NOMEM@ is
92 extern char *x_strdup(arena */*a*/, const char */*s*/);
94 /* --- @x_realloc@ --- *
96 * Arguments: @arena *a@ = pointer to underlying arena
97 * @void *p@ = pointer to a block of memory
98 * @size_t sz@ = new size desired for the block
100 * Returns: Pointer to the resized memory block (which is almost
101 * certainly not in the same place any more).
103 * Use: Resizes a memory block. If there's not enough memory, the
104 * exception @EXC_NOMEM@ is thrown.
107 extern void *x_realloc(arena */*a*/, void */*p*/, size_t /*sz*/);
109 /* --- @x_free@ --- *
111 * Arguments: @arena *a@ = pointer to underlying arena
112 * @void *p@ = pointer to a block of memory.
116 * Use: Frees a block of memory.
119 extern void x_free(arena */*a*/, void */*p*/);
120 #define x_free(a, p) A_FREE(a, p)
122 /*----- Old functions for the standard arena ------------------------------*/
124 /* --- @xmalloc@ --- *
126 * Arguments: @size_t sz@ = size of block to allocate
128 * Returns: Pointer to allocated block.
130 * Use: Allocates memory. If there's not enough memory, the
131 * exception @EXC_NOMEM@ is thrown.
134 extern void *xmalloc(size_t /*sz*/);
135 #define xmalloc(sz) x_alloc(arena_global, (sz))
137 /* --- @xstrdup@ --- *
139 * Arguments: @const char *s@ = pointer to a string
141 * Returns: Pointer to a copy of the string.
143 * Use: Copies a string (like @strdup@ would, if it existed). If
144 * there's not enough memory, the exception @EXC_NOMEM@ is
148 extern char *xstrdup(const char */*s*/);
149 #define xstrdup(p) x_strdup(arena_global, (p))
151 /* --- @xrealloc@ --- *
153 * Arguments: @void *p@ = pointer to a block of memory
154 * @size_t sz@ = new size desired for the block
156 * Returns: Pointer to the resized memory block (which is almost
157 * certainly not in the same place any more).
159 * Use: Resizes a memory block. If there's not enough memory, the
160 * exception @EXC_NOMEM@ is thrown.
163 extern void *xrealloc(void */*p*/, size_t /*sz*/);
164 #define xrealloc(p, sz) x_realloc(arena_global, (p), (sz))
168 * Arguments: @void *p@ = pointer to a block of memory.
172 * Use: Frees a block of memory.
175 extern void xfree(void */*p*/);
176 #define xfree(p) x_free(arena_global, (p))
178 /*----- That's all, folks -------------------------------------------------*/