mempool: add k_calloc()
This uses the kernel heap to implement traditional calloc() semantics. Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
parent
539d2af654
commit
7f95e83361
2 changed files with 26 additions and 0 deletions
|
@ -3704,6 +3704,19 @@ extern void *k_malloc(size_t size);
|
|||
*/
|
||||
extern void k_free(void *ptr);
|
||||
|
||||
/**
|
||||
* @brief Allocate memory from heap, array style
|
||||
*
|
||||
* This routine provides traditional calloc() semantics. Memory is
|
||||
* allocated from the heap memory pool and zeroed.
|
||||
*
|
||||
* @param nmemb Number of elements in the requested array
|
||||
* @param size Size of each array element (in bytes).
|
||||
*
|
||||
* @return Address of the allocated memory if successful; otherwise NULL.
|
||||
*/
|
||||
extern void *k_calloc(size_t nmemb, size_t size);
|
||||
|
||||
/**
|
||||
* @} end defgroup heap_apis
|
||||
*/
|
||||
|
|
|
@ -405,4 +405,17 @@ void k_free(void *ptr)
|
|||
k_mem_pool_free(ptr);
|
||||
}
|
||||
}
|
||||
|
||||
void *k_calloc(size_t nmemb, size_t size)
|
||||
{
|
||||
void *ret;
|
||||
size_t bounds;
|
||||
|
||||
bounds = nmemb * size;
|
||||
ret = k_malloc(bounds);
|
||||
if (ret) {
|
||||
memset(ret, 0, bounds);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue