ucx/allocator.h

changeset 173
31a8682fffb7
parent 146
aa376dba1ba8
child 174
bbfe511cfddb
     1.1 --- a/ucx/allocator.h	Mon Jun 02 16:04:11 2014 +0200
     1.2 +++ b/ucx/allocator.h	Tue Jun 10 15:43:13 2014 +0200
     1.3 @@ -157,6 +157,41 @@
     1.4  void ucx_default_free(void *ignore, void *data);
     1.5  
     1.6  /**
     1.7 + * Shorthand for calling an allocators malloc function.
     1.8 + * @param allocator the allocator to use
     1.9 + * @param n size of space to allocate
    1.10 + * @return a pointer to the allocated memory area
    1.11 + */
    1.12 +#define almalloc(allocator, n) ((allocator)->malloc(allocator->pool, n))
    1.13 +
    1.14 +/**
    1.15 + * Shorthand for calling an allocators calloc function.
    1.16 + * @param allocator the allocator to use
    1.17 + * @param n the count of elements the space should be allocated for
    1.18 + * @param size the size of each element
    1.19 + * @return a pointer to the allocated memory area
    1.20 + */
    1.21 +#define alcalloc(allocator, n, size) \
    1.22 +        ((allocator)->calloc(allocator->pool, n, size))
    1.23 +
    1.24 +/**
    1.25 + * Shorthand for calling an allocators realloc function.
    1.26 + * @param allocator the allocator to use
    1.27 + * @param ptr the pointer to the memory area that shall be reallocated
    1.28 + * @param n the new size of the allocated memory area
    1.29 + * @return a pointer to the reallocated memory area
    1.30 + */
    1.31 +#define alrealloc(allocator, ptr, n) \
    1.32 +        ((allocator)->realloc(allocator->pool, ptr, n))
    1.33 +
    1.34 +/**
    1.35 + * Shorthand for calling an allocators free function.
    1.36 + * @param allocator the allocator to use
    1.37 + * @param ptr the pointer to the memory area that shall be freed
    1.38 + */
    1.39 +#define alfree(allocator, ptr) ((allocator)->free(allocator->pool, ptr))
    1.40 +
    1.41 +/**
    1.42   * Convenient macro for a default allocator <code>struct</code> definition.
    1.43   */
    1.44  #define UCX_ALLOCATOR_DEFAULT {NULL, \

mercurial