chiark / gitweb /
Experimental new support for packet buffering.
[mLib] / alloc.h
CommitLineData
0875b58f 1/* -*-c-*-
2 *
0fd574c3 3 * $Id: alloc.h,v 1.5 2000/06/17 10:35:51 mdw Exp $
0875b58f 4 *
5 * Memory allocation functions
6 *
7 * (c) 1998 Straylight/Edgeware
8 */
9
c846879c 10/*----- Licensing notice --------------------------------------------------*
0875b58f 11 *
12 * This file is part of the mLib utilities library.
13 *
14 * mLib is free software; you can redistribute it and/or modify
c846879c 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.
18 *
0875b58f 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
c846879c 22 * GNU Library General Public License for more details.
23 *
24 * You should have received a copy of the GNU Library General Public
0bd98442 25 * License along with mLib; if not, write to the Free
26 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
27 * MA 02111-1307, USA.
0875b58f 28 */
29
30/*----- Revision history --------------------------------------------------*
31 *
32 * $Log: alloc.h,v $
0fd574c3 33 * Revision 1.5 2000/06/17 10:35:51 mdw
34 * Major overhaul for arena support.
35 *
c6e0eaf0 36 * Revision 1.4 1999/12/10 23:42:04 mdw
37 * Change header file guard names.
38 *
0bd98442 39 * Revision 1.3 1999/05/06 19:51:35 mdw
40 * Reformatted the LGPL notice a little bit.
41 *
c846879c 42 * Revision 1.2 1999/05/05 18:50:31 mdw
43 * Change licensing conditions to LGPL.
44 *
45 * Revision 1.1.1.1 1998/06/17 23:44:42 mdw
46 * Initial version of mLib
0875b58f 47 *
48 */
49
c6e0eaf0 50#ifndef MLIB_ALLOC_H
51#define MLIB_ALLOC_H
0875b58f 52
53#ifdef __cplusplus
54 extern "C" {
55#endif
56
0fd574c3 57/*----- Required header files ---------------------------------------------*/
58
0875b58f 59#include <stddef.h>
60
0fd574c3 61#ifndef MLIB_ARENA_H
62# include "arena.h"
63#endif
64
65/*----- Functions and macros ----------------------------------------------*/
66
67/* --- @x_alloc@ --- *
68 *
69 * Arguments: @arena *a@ = pointer to underlying arena
70 * @size_t sz@ = size of block to allocate
71 *
72 * Returns: Pointer to allocated block.
73 *
74 * Use: Allocates memory. If there's not enough memory, the
75 * exception @EXC_NOMEM@ is thrown.
76 */
77
78extern void *x_alloc(arena */*a*/, size_t /*sz*/);
79
80/* --- @x_strdup@ --- *
81 *
82 * Arguments: @arena *a@ = pointer to underlying arena
83 * @const char *s@ = pointer to a string
84 *
85 * Returns: Pointer to a copy of the string.
86 *
87 * Use: Copies a string (like @strdup@ would, if it existed). If
88 * there's not enough memory, the exception @EXC_NOMEM@ is
89 * thrown.
90 */
91
92extern char *x_strdup(arena */*a*/, const char */*s*/);
93
94/* --- @x_realloc@ --- *
95 *
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
99 *
100 * Returns: Pointer to the resized memory block (which is almost
101 * certainly not in the same place any more).
102 *
103 * Use: Resizes a memory block. If there's not enough memory, the
104 * exception @EXC_NOMEM@ is thrown.
105 */
106
107extern void *x_realloc(arena */*a*/, void */*p*/, size_t /*sz*/);
108
109/* --- @x_free@ --- *
110 *
111 * Arguments: @arena *a@ = pointer to underlying arena
112 * @void *p@ = pointer to a block of memory.
113 *
114 * Returns: ---
115 *
116 * Use: Frees a block of memory.
117 */
118
119extern void x_free(arena */*a*/, void */*p*/);
120#define x_free(a, p) A_FREE(a, p)
121
122/*----- Old functions for the standard arena ------------------------------*/
0875b58f 123
124/* --- @xmalloc@ --- *
125 *
126 * Arguments: @size_t sz@ = size of block to allocate
127 *
128 * Returns: Pointer to allocated block.
129 *
130 * Use: Allocates memory. If there's not enough memory, the
131 * exception @EXC_NOMEM@ is thrown.
132 */
133
134extern void *xmalloc(size_t /*sz*/);
0fd574c3 135#define xmalloc(sz) x_alloc(arena_global, (sz))
0875b58f 136
137/* --- @xstrdup@ --- *
138 *
139 * Arguments: @const char *s@ = pointer to a string
140 *
141 * Returns: Pointer to a copy of the string.
142 *
143 * Use: Copies a string (like @strdup@ would, if it existed). If
144 * there's not enough memory, the exception @EXC_NOMEM@ is
145 * thrown.
146 */
147
148extern char *xstrdup(const char */*s*/);
0fd574c3 149#define xstrdup(p) x_strdup(arena_global, (p))
0875b58f 150
151/* --- @xrealloc@ --- *
152 *
153 * Arguments: @void *p@ = pointer to a block of memory
154 * @size_t sz@ = new size desired for the block
155 *
156 * Returns: Pointer to the resized memory block (which is almost
157 * certainly not in the same place any more).
158 *
159 * Use: Resizes a memory block. If there's not enough memory, the
160 * exception @EXC_NOMEM@ is thrown.
161 */
162
163extern void *xrealloc(void */*p*/, size_t /*sz*/);
0fd574c3 164#define xrealloc(p, sz) x_realloc(arena_global, (p), (sz))
165
166/* --- @xfree@ --- *
167 *
168 * Arguments: @void *p@ = pointer to a block of memory.
169 *
170 * Returns: ---
171 *
172 * Use: Frees a block of memory.
173 */
174
175extern void xfree(void */*p*/);
176#define xfree(p) x_free(arena_global, (p))
0875b58f 177
178/*----- That's all, folks -------------------------------------------------*/
179
180#ifdef __cplusplus
181 }
182#endif
183
184#endif