3 * $Id: alloc.h,v 1.6 2000/07/16 12:29:16 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.6 2000/07/16 12:29:16 mdw
34 * Change to arena `realloc' interface, to fix a design bug.
36 * Revision 1.5 2000/06/17 10:35:51 mdw
37 * Major overhaul for arena support.
39 * Revision 1.4 1999/12/10 23:42:04 mdw
40 * Change header file guard names.
42 * Revision 1.3 1999/05/06 19:51:35 mdw
43 * Reformatted the LGPL notice a little bit.
45 * Revision 1.2 1999/05/05 18:50:31 mdw
46 * Change licensing conditions to LGPL.
48 * Revision 1.1.1.1 1998/06/17 23:44:42 mdw
49 * Initial version of mLib
60 /*----- Required header files ---------------------------------------------*/
68 /*----- Functions and macros ----------------------------------------------*/
70 /* --- @x_alloc@ --- *
72 * Arguments: @arena *a@ = pointer to underlying arena
73 * @size_t sz@ = size of block to allocate
75 * Returns: Pointer to allocated block.
77 * Use: Allocates memory. If there's not enough memory, the
78 * exception @EXC_NOMEM@ is thrown.
81 extern void *x_alloc(arena */
*a*/
, size_t /*sz*/);
83 /* --- @x_strdup@ --- *
85 * Arguments: @arena *a@ = pointer to underlying arena
86 * @const char *s@ = pointer to a string
88 * Returns: Pointer to a copy of the string.
90 * Use: Copies a string (like @strdup@ would, if it existed). If
91 * there's not enough memory, the exception @EXC_NOMEM@ is
95 extern char *x_strdup(arena */
*a*/
, const char */
*s*/
);
97 /* --- @x_realloc@ --- *
99 * Arguments: @arena *a@ = pointer to underlying arena
100 * @void *p@ = pointer to a block of memory
101 * @size_t sz@ = new size desired for the block
102 * @size_t osz@ = size of the old block
104 * Returns: Pointer to the resized memory block (which is almost
105 * certainly not in the same place any more).
107 * Use: Resizes a memory block. If there's not enough memory, the
108 * exception @EXC_NOMEM@ is thrown.
111 extern void *x_realloc(arena */
*a*/
, void */
*p*/
,
112 size_t /*sz*/, size_t /*osz*/);
114 /* --- @x_free@ --- *
116 * Arguments: @arena *a@ = pointer to underlying arena
117 * @void *p@ = pointer to a block of memory.
121 * Use: Frees a block of memory.
124 extern void x_free(arena */
*a*/
, void */
*p*/
);
125 #define x_free(a, p) A_FREE(a, p)
127 /*----- Old functions for the standard arena ------------------------------*/
129 /* --- @xmalloc@ --- *
131 * Arguments: @size_t sz@ = size of block to allocate
133 * Returns: Pointer to allocated block.
135 * Use: Allocates memory. If there's not enough memory, the
136 * exception @EXC_NOMEM@ is thrown.
139 extern void *xmalloc(size_t /*sz*/);
140 #define xmalloc(sz) x_alloc(arena_global, (sz))
142 /* --- @xstrdup@ --- *
144 * Arguments: @const char *s@ = pointer to a string
146 * Returns: Pointer to a copy of the string.
148 * Use: Copies a string (like @strdup@ would, if it existed). If
149 * there's not enough memory, the exception @EXC_NOMEM@ is
153 extern char *xstrdup(const char */
*s*/
);
154 #define xstrdup(p) x_strdup(arena_global, (p))
156 /* --- @xrealloc@ --- *
158 * Arguments: @void *p@ = pointer to a block of memory
159 * @size_t sz@ = new size desired for the block
160 * @size_t osz@ = size of the old block
162 * Returns: Pointer to the resized memory block (which is almost
163 * certainly not in the same place any more).
165 * Use: Resizes a memory block. If there's not enough memory, the
166 * exception @EXC_NOMEM@ is thrown.
169 extern void *xrealloc(void */
*p*/
, size_t /*sz*/, size_t /*osz*/);
170 #define xrealloc(p, sz, osz) x_realloc(arena_global, (p), (sz), (osz))
174 * Arguments: @void *p@ = pointer to a block of memory.
178 * Use: Frees a block of memory.
181 extern void xfree(void */
*p*/
);
182 #define xfree(p) x_free(arena_global, (p))
184 /*----- That's all, folks -------------------------------------------------*/