Allocate user memory

To handle dynamic memory allocation of user memory, use one of the following DataBlade® API memory-management functions.
Memory-Allocation Task DataBlade API Function
To allocate user memory mi_alloc()
To allocate user memory with a specified memory duration (memory duration is ignored) mi_dalloc()
To allocate user memory that is filled with zeros mi_zalloc()
To change the size of existing memory or allocate new user memory mi_realloc()

In client LIBMI applications, mi_dalloc() works exactly like malloc(): storage is allocated on the heap of the client process. However, this memory has no memory duration associated with it; that is, the database server does not automatically free this memory. Therefore, the client LIBMI application must use mi_free() to free explicitly all allocations that mi_dalloc() makes.

The mi_alloc() and mi_zalloc() functions return a pointer to the newly allocated memory. Cast this pointer to match the structure of the user-defined buffer or structure that you allocate. For example, the following call to mi_dalloc() casts the pointer to the allocated memory as a pointer to a structure named func_info and uses this pointer to access the count_fld of the func_info structure:
#include mitypes.h
...
struct func_info *fi_ptr;
mi_integer count;
...
fi_ptr = (func_info *)mi_dalloc(sizeof(func_info),
    PER_COMMAND);
fi_ptr->count_fld = 3;

The mi_realloc() function accepts a pointer to existing memory and a parameter specifying the number of bytes reallocate to that memory. The function returns a pointer to the reallocated memory. If the pointer to existing memory is NULL, then mi_realloc() allocates new memory in the same way as mi_alloc().

The mi_switch_mem_duration() function has no effect when it is invoked in a client LIBMI application. Client LIBMI applications ignore memory duration.