0875b58f |
1 | /* -*-c-*- |
2 | * |
0bd98442 |
3 | * $Id: sub.h,v 1.3 1999/05/06 19:51:35 mdw Exp $ |
0875b58f |
4 | * |
5 | * Allocation of known-size blocks |
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: sub.h,v $ |
0bd98442 |
33 | * Revision 1.3 1999/05/06 19:51:35 mdw |
34 | * Reformatted the LGPL notice a little bit. |
35 | * |
c846879c |
36 | * Revision 1.2 1999/05/05 18:50:31 mdw |
37 | * Change licensing conditions to LGPL. |
38 | * |
39 | * Revision 1.1.1.1 1998/06/17 23:44:42 mdw |
40 | * Initial version of mLib |
0875b58f |
41 | * |
42 | */ |
43 | |
44 | #ifndef SUB_H |
45 | #define SUB_H |
46 | |
47 | #ifdef __cplusplus |
48 | extern "C" { |
49 | #endif |
50 | |
51 | /*----- Required header files ---------------------------------------------*/ |
52 | |
53 | #include <stdlib.h> |
54 | |
55 | #ifndef ALLOC_H |
56 | # include "alloc.h" |
57 | #endif |
58 | |
59 | /*----- Functions provided ------------------------------------------------*/ |
60 | |
61 | /* --- @sub_alloc@ --- * |
62 | * |
63 | * Arguments: @size_t s@ = size of chunk wanted |
64 | * |
65 | * Returns: Pointer to a block at least as large as the one wanted. |
66 | * |
67 | * Use: Allocates a small block of memory. If there is no more |
68 | * memory left, the exception @EXC_NOMEM@ is raised. |
69 | */ |
70 | |
71 | #ifdef TRACK_ENABLE |
72 | # define sub_alloc(s) xmalloc(s) |
73 | #else |
74 | void *sub_alloc(size_t s); |
75 | #endif |
76 | |
77 | /* --- @sub_free@ --- * |
78 | * |
79 | * Arguments: @void *p@ = address of block to free |
80 | * @size_t s@ = size of block |
81 | * |
82 | * Returns: --- |
83 | * |
84 | * Use: Frees a block allocated by @sub_alloc@. |
85 | */ |
86 | |
87 | #ifdef TRACK_ENABLE |
88 | # define sub_free(p, s) free(p) |
89 | #else |
90 | void sub_free(void *p, size_t s); |
91 | #endif |
92 | |
93 | /* --- @CREATE@ --- * |
94 | * |
95 | * Arguments: @type@ = type of object required; must be passable to |
96 | * @sizeof@ |
97 | * |
98 | * Returns: Pointer to a block sufficiently big to hold an object of the |
99 | * named type. |
100 | * |
101 | * Use: Allocates a block of the required type. |
102 | */ |
103 | |
104 | #define CREATE(type) sub_alloc(sizeof(type)) |
105 | |
106 | /* --- @DESTROY@ --- * |
107 | * |
108 | * Arguments: @void *p@ = pointer to an object |
109 | * |
110 | * Returns: --- |
111 | * |
112 | * Use: Frees the thing pointed to by @p@. |
113 | */ |
114 | |
115 | #define DESTROY(p) sub_free(p, sizeof(*p)) |
116 | |
117 | /* --- @sub_init@ --- * |
118 | * |
119 | * Arguments: --- |
120 | * |
121 | * Returns: --- |
122 | * |
123 | * Use: Initialises the magic allocator. |
124 | */ |
125 | |
126 | void sub_init(void); |
127 | |
128 | /*----- That's all, folks -------------------------------------------------*/ |
129 | |
130 | #ifdef __cplusplus |
131 | } |
132 | #endif |
133 | |
134 | #endif |