porting/dpl_lib/src/dpl_mem.c
/**
 * Mallocs a block of memory and initializes a mempool to use it.
 *
 * @param mempool               The mempool to initialize.
 * @param num_blocks            The total number of memory blocks in the
 *                                  mempool.
 * @param block_size            The size of each mempool entry.
 * @param name                  The name to give the mempool.
 * @param out_buf               On success, this points to the malloced memory.
 *                                  Pass NULL if you don't need this
 *                                  information.
 *
 * @return                      0 on success;
 *                              DPL_ENOMEM on malloc failure;
 *                              Other OS code on unexpected error.
 */
Mallocs a block of memory and initializes a mempool to use it.
@param mempool               The mempool to initialize.
@param num_blocks            The total number of memory blocks in the
mempool.
@param block_size            The size of each mempool entry.
@param name                  The name to give the mempool.
@param out_buf               On success, this points to the malloced memory.
Pass NULL if you don't need this
information.

@return                      0 on success;
DPL_ENOMEM on malloc failure;
Other OS code on unexpected error.
Mallocs a block of memory and initializes a mempool to use it . @param mempool The mempool to initialize . @param num_blocks The total number of memory blocks in the mempool . @param block_size The size of each mempool entry . @param name The name to give the mempool . @param out_buf On success this points to the malloced memory . Pass NULL if you don ' t need this information . @return 0 on success ; DPL_ENOMEM on malloc failure ; Other OS code on unexpected error .
int
mem_malloc_mempool(struct dpl_mempool *mempool, uint16_t num_blocks,
                   uint32_t block_size, char *name, void **out_buf)
{
    void *buf;
    int rc;
    rc = mem_malloc_mempool_gen(num_blocks, block_size, &buf);
    if (rc != 0) {
        return rc;
    }
    rc = dpl_mempool_init(mempool, num_blocks, block_size, buf, name);
    if (rc != 0) {
        free(buf);
        return rc;
    }
    if (out_buf != NULL) {
        *out_buf = buf;
    }
    return 0;
}
int mem_malloc_mempool ( struct dpl_mempool * mempool , uint16_t num_blocks , uint32_t block_size , char * name , void * * out_buf ) { void * buf ; int rc ; rc = mem_malloc_mempool_gen ( num_blocks , block_size , & buf ) ; if ( rc != 0 ) { return rc ; } rc = dpl_mempool_init ( mempool , num_blocks , block_size , buf , name ) ; if ( rc != 0 ) { free ( buf ) ; return rc ; } if ( out_buf != NULL ) { * out_buf = buf ; } return 0 ; }
Mallocs a block of memory and initializes a mempool to use it.
Mallocs a block of memory and initializes a mempool to use it .