@@ -101,8 +101,7 @@ typedef uint8_t heapmem_zone_t;
101
101
102
102
/**
103
103
* \brief Register a zone with a reserved subdivision of the heap.
104
- * \param name A pointer to a chunk that has been allocated using
105
- * heapmem_alloc() or heapmem_realloc().
104
+ * \param name A string containing the name of the zone.
106
105
* \param zone_size The number of bytes to reserve for the zone.
107
106
* \return A zone ID if the allocation succeeds, or
108
107
* HEAPMEM_ZONE_INVALID if it fails.
@@ -112,17 +111,25 @@ heapmem_zone_t heapmem_zone_register(const char *name, size_t zone_size);
112
111
113
112
#if HEAPMEM_DEBUG
114
113
115
- #define heapmem_alloc (size ) heapmem_zone_alloc_debug(HEAPMEM_ZONE_GENERAL, (size), __FILE__, __LINE__)
116
- #define heapmem_zone_alloc (zone , size ) heapmem_zone_alloc_debug((zone), (size), __FILE__, __LINE__)
117
- #define heapmem_realloc (ptr , size ) heapmem_realloc_debug((ptr), (size), __FILE__, __LINE__)
118
- #define heapmem_free (ptr ) heapmem_free_debug((ptr), __FILE__, __LINE__)
114
+ #define heapmem_alloc (size ) \
115
+ heapmem_zone_alloc_debug(HEAPMEM_ZONE_GENERAL, (size), __FILE__, __LINE__)
116
+ #define heapmem_zone_alloc (zone , size ) \
117
+ heapmem_zone_alloc_debug((zone), (size), __FILE__, __LINE__)
118
+ #define heapmem_realloc (ptr , size ) \
119
+ heapmem_realloc_debug((ptr), (size), __FILE__, __LINE__)
120
+ #define heapmem_calloc (nmemb , size ) \
121
+ heapmem_calloc_debug((nmemb), (size), __FILE__, __LINE__)
122
+ #define heapmem_free (ptr ) \
123
+ heapmem_free_debug((ptr), __FILE__, __LINE__)
119
124
120
125
void * heapmem_alloc_debug (size_t size ,
121
126
const char * file , const unsigned line );
122
127
void * heapmem_zone_alloc_debug (heapmem_zone_t zone , size_t size ,
123
128
const char * file , const unsigned line );
124
129
void * heapmem_realloc_debug (void * ptr , size_t size ,
125
130
const char * file , const unsigned line );
131
+ void * heapmem_calloc_debug (size_t nmemb , size_t size ,
132
+ const char * file , const unsigned line );
126
133
bool heapmem_free_debug (void * ptr ,
127
134
const char * file , const unsigned line );
128
135
@@ -137,7 +144,6 @@ bool heapmem_free_debug(void *ptr,
137
144
* \sa heapmem_realloc
138
145
* \sa heapmem_free
139
146
*/
140
-
141
147
#define heapmem_alloc (size ) heapmem_zone_alloc(HEAPMEM_ZONE_GENERAL, (size))
142
148
143
149
/**
@@ -155,7 +161,7 @@ void *heapmem_zone_alloc(heapmem_zone_t zone, size_t size);
155
161
/**
156
162
* \brief Reallocate a chunk of memory in the heap.
157
163
* \param ptr A pointer to a chunk that has been allocated using
158
- * heapmem_alloc() or heapmem_realloc().
164
+ * heapmem_alloc(), heapmem_calloc(), or heapmem_realloc().
159
165
* \param size The number of bytes to allocate.
160
166
* \return A pointer to the allocated memory chunk,
161
167
* or NULL if the allocation failed.
@@ -165,24 +171,36 @@ void *heapmem_zone_alloc(heapmem_zone_t zone, size_t size);
165
171
* the chunk and returns NULL.
166
172
*
167
173
* \sa heapmem_alloc
174
+ * \sa heapmem_calloc
168
175
* \sa heapmem_free
169
176
*/
170
-
171
177
void * heapmem_realloc (void * ptr , size_t size );
172
178
179
+ /**
180
+ * \brief Allocate memory for a zero-initialized array.
181
+ * \param nmemb The number of elements to allocate.
182
+ * \param size The size of each element.
183
+ * \return A pointer to the allocated memory,
184
+ * or NULL if the allocation failed.
185
+ *
186
+ * \sa heapmem_alloc
187
+ * \sa heapmem_free
188
+ */
189
+ void * heapmem_calloc (size_t nmemb , size_t size );
190
+
173
191
/**
174
192
* \brief Deallocate a chunk of memory.
175
193
* \param ptr A pointer to a chunk that has been allocated using
176
- * heapmem_alloc() or heapmem_realloc().
194
+ * heapmem_alloc(), heapmem_calloc(), or heapmem_realloc().
177
195
* \return A boolean indicating whether the memory could be deallocated.
178
196
*
179
197
* \note If ptr is NULL, this function will return immediately without
180
198
* performing any action.
181
199
*
182
200
* \sa heapmem_alloc
201
+ * \sa heapmem_calloc
183
202
* \sa heapmem_realloc
184
203
*/
185
-
186
204
bool heapmem_free (void * ptr );
187
205
188
206
#endif /* HEAPMEM_DEBUG */
@@ -199,14 +217,12 @@ bool heapmem_free(void *ptr);
199
217
* and the number of chunks allocated. By using this information, developers
200
218
* can tune their software to use the heapmem allocator more efficiently.
201
219
*/
202
-
203
220
void heapmem_stats (heapmem_stats_t * stats );
204
221
205
222
/**
206
223
* \brief Obtain the minimum alignment of allocated addresses.
207
224
* \return The alignment value, which is a power of two.
208
225
*/
209
-
210
226
size_t heapmem_alignment (void );
211
227
212
228
#endif /* !HEAPMEM_H */
0 commit comments