Allocate user memory
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.
#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.