From afdbaf8651108623ba3e187d354e0397d2d44fdd Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Fri, 2 Dec 2011 15:27:35 +0000 Subject: [PATCH] +eina_mempool_calloc SVN revision: 65821 --- legacy/eina/ChangeLog | 4 ++++ legacy/eina/NEWS | 10 ++++++++ legacy/eina/src/include/eina_inline_mempool.x | 23 +++++++++++++++++++ 3 files changed, 37 insertions(+) diff --git a/legacy/eina/ChangeLog b/legacy/eina/ChangeLog index 0d1ccdfed8..a67006a92a 100644 --- a/legacy/eina/ChangeLog +++ b/legacy/eina/ChangeLog @@ -147,3 +147,7 @@ * Add new hash function eina_hash_murmur3 that should be better at hashing strings. + +2011-12-02 Mike Blumenkrantz (discomfitor/zmike) + + * Add eina_mempool_calloc for returning zeroed memory diff --git a/legacy/eina/NEWS b/legacy/eina/NEWS index 6f9a0ef68d..ca39236d6e 100644 --- a/legacy/eina/NEWS +++ b/legacy/eina/NEWS @@ -1,3 +1,13 @@ +Eina 1.2.0 + +Changes since Eina 1.1.0: +------------------------- + +Additions: + + * eina_mempool_calloc + + Eina 1.1.0 Changes since Eina 1.0.0: diff --git a/legacy/eina/src/include/eina_inline_mempool.x b/legacy/eina/src/include/eina_inline_mempool.x index a67ec3d12a..c71413ec97 100644 --- a/legacy/eina/src/include/eina_inline_mempool.x +++ b/legacy/eina/src/include/eina_inline_mempool.x @@ -19,6 +19,8 @@ #ifndef EINA_INLINE_MEMPOOL_X_ #define EINA_INLINE_MEMPOOL_X_ +#include + /** * @addtogroup Eina_Memory_Pool_Group Memory Pool * @@ -103,6 +105,27 @@ eina_mempool_malloc(Eina_Mempool *mp, unsigned int size) return mp->backend.alloc(mp->backend_data, size); } +/** + * @brief Allocate and zero a amount memory by the given mempool. + * + * @param mp The mempool. + * @param size The size in bytes to allocate. + * @return The newly allocated data. + * + * This function allocates @p size bytes, using the mempool @p mp and + * returns the allocated data after zeroing it. If not used anymore, + * the data must be freed with eina_mempool_free(). No check is done on @p mp, + * so it must be a valid mempool. + */ +static inline void * +eina_mempool_calloc(Eina_Mempool *mp, unsigned int size) +{ + void *r = mp->backend.alloc(mp->backend_data, size); + if (!r) return NULL; + memset(r, 0, size); + return r; +} + /** * @brief Free the allocated ressources by the given mempool. *