mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-27 23:41:18 +01:00
Merge pull request #14930 from bergzand/pr/memarray/calloc
memarray: Add memarray_calloc
This commit is contained in:
commit
b584a2dadf
@ -54,6 +54,8 @@ void memarray_init(memarray_t *mem, void *data, size_t size, size_t num);
|
||||
*
|
||||
* @pre `mem != NULL`
|
||||
*
|
||||
* @note Allocated structure is not cleared before returned
|
||||
*
|
||||
* @param[in,out] mem memarray pool to allocate block in
|
||||
*
|
||||
* @return pointer to allocated structure, if enough memory was available
|
||||
@ -61,6 +63,18 @@ void memarray_init(memarray_t *mem, void *data, size_t size, size_t num);
|
||||
*/
|
||||
void *memarray_alloc(memarray_t *mem);
|
||||
|
||||
/**
|
||||
* @brief Allocate and clear memory chunk in memarray pool
|
||||
*
|
||||
* @pre `mem != NULL`
|
||||
*
|
||||
* @param[in,out] mem memarray pool to allocate block in
|
||||
*
|
||||
* @return pointer to allocated structure, if enough memory was available
|
||||
* @return NULL, on failure
|
||||
*/
|
||||
void *memarray_calloc(memarray_t *mem);
|
||||
|
||||
/**
|
||||
* @brief Free memory chunk in memarray pool
|
||||
*
|
||||
|
||||
@ -44,6 +44,15 @@ void *memarray_alloc(memarray_t *mem)
|
||||
return free;
|
||||
}
|
||||
|
||||
void *memarray_calloc(memarray_t *mem)
|
||||
{
|
||||
void *new = memarray_alloc(mem);
|
||||
if (new) {
|
||||
memset(new, 0, mem->size);
|
||||
}
|
||||
return new;
|
||||
}
|
||||
|
||||
void memarray_free(memarray_t *mem, void *ptr)
|
||||
{
|
||||
assert((mem != NULL) && (ptr != NULL));
|
||||
|
||||
@ -58,12 +58,10 @@ static cn_cbor_context ct =
|
||||
static void *cbor_calloc(size_t count, size_t size, void *memblock)
|
||||
{
|
||||
(void)count;
|
||||
(void)size;
|
||||
expect(count == 1); /* Count is always 1 with cn-cbor */
|
||||
void *block = memarray_alloc(memblock);
|
||||
if (block) {
|
||||
memset(block, 0, size);
|
||||
}
|
||||
return block;
|
||||
expect(size == sizeof(cn_cbor));
|
||||
return memarray_calloc(memblock);
|
||||
}
|
||||
|
||||
static void cbor_free(void *ptr, void *memblock)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user