summaryrefslogtreecommitdiff
path: root/pjlib
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2007-02-21 00:40:05 +0000
committerBenny Prijono <bennylp@teluu.com>2007-02-21 00:40:05 +0000
commit1a5b8c19989c4ab4e1eee7f712913f8f3e459e71 (patch)
tree94d7851e91849c6b60420150c8944db9bcf4b298 /pjlib
parentb69a9ab56a1df4a41bfa9132d5aa5263fa80b38b (diff)
Merged the ICE branch into the trunk
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@992 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjlib')
-rw-r--r--pjlib/include/pj/pool.h40
1 files changed, 38 insertions, 2 deletions
diff --git a/pjlib/include/pj/pool.h b/pjlib/include/pj/pool.h
index b3ec5afd..e4225905 100644
--- a/pjlib/include/pj/pool.h
+++ b/pjlib/include/pj/pool.h
@@ -441,6 +441,8 @@ PJ_IDECL(pj_size_t) pj_pool_get_used_size( pj_pool_t *pool );
* @param size the requested size.
*
* @return pointer to the allocated memory.
+ *
+ * @see PJ_POOL_ALLOC_TYPE
*/
PJ_IDECL(void*) pj_pool_alloc( pj_pool_t *pool, pj_size_t size);
@@ -460,15 +462,49 @@ PJ_IDECL(void*) pj_pool_calloc( pj_pool_t *pool, pj_size_t count,
/**
- * @def pj_pool_zalloc(pj_pool_t *pool, pj_size_t size)
* Allocate storage from the pool and initialize it to zero.
*
* @param pool The pool.
* @param size The size to be allocated.
*
* @return Pointer to the allocated memory.
+ *
+ * @see PJ_POOL_ZALLOC_TYPE
+ */
+PJ_INLINE(void*) pj_pool_zalloc(pj_pool_t *pool, pj_size_t size)
+{
+ return pj_pool_calloc(pool, 1, size);
+}
+
+
+/**
+ * This macro allocates memory from the pool and returns the instance of
+ * the specified type. It provides a stricker type safety than pj_pool_alloc()
+ * since the return value of this macro will be type-casted to the specified
+ * type.
+ *
+ * @param pool The pool
+ * @param type The type of object to be allocated
+ *
+ * @return Memory buffer of the specified type.
+ */
+#define PJ_POOL_ALLOC_TYPE(pool,type) \
+ ((type*)pj_pool_alloc(pool, sizeof(type)))
+
+/**
+ * This macro allocates memory from the pool, zeroes the buffer, and
+ * returns the instance of the specified type. It provides a stricker type
+ * safety than pj_pool_zalloc() since the return value of this macro will be
+ * type-casted to the specified type.
+ *
+ * @param pool The pool
+ * @param type The type of object to be allocated
+ *
+ * @return Memory buffer of the specified type.
*/
-#define pj_pool_zalloc(pool, size) pj_pool_calloc(pool, 1, size)
+#define PJ_POOL_ZALLOC_TYPE(pool,type) \
+ ((type*)pj_pool_zalloc(pool, sizeof(type)))
+
/**