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