The mi_alloc() function
The mi_alloc() function allocates a block of user memory of a specified size and returns a pointer to that block.
Syntax
void *mi_alloc(size)
mi_integer size;
- size
- The number of bytes to allocate.
Valid in client LIBMI application? | Valid in user-defined routine? |
---|---|
Yes | Yes |
Usage
The mi_alloc() function allocates size number of bytes of user memory for a DataBlade® API module. The mi_alloc() function is a constructor function for user memory.
- Use mi_dalloc() instead of mi_alloc() to
allocate memory.
The mi_dalloc() function works in the same way as mi_alloc() and provides the option of specifying the duration.
- Call mi_switch_mem_duration() before you call mi_alloc().
The mi_switch_mem_duration() function changes the current memory duration for all subsequent memory allocations.
Client LIBMI applications can use either DataBlade® API memory-management functions or system memory-management functions (such as malloc()).
The mi_alloc() function returns a pointer to the newly allocated user memory. Cast this pointer to match the structure of the user-defined buffer or structure that you allocate. A DataBlade® API module can use mi_free() to free memory allocated by mi_alloc() when that memory is no longer needed.
Return values
- A void pointer
- A pointer to the newly allocated memory. Cast this pointer to match the user-defined buffer or structure for which the memory was allocated.
- NULL
- The function was unable to allocate the memory.
The mi_alloc() function does not throw an MI_Exception event when it encounters a runtime error. Therefore, it does not cause callbacks to be invoked.
For more information, see the discussion on how to allocate user memory in the Informix® DataBlade® API Programmer's Guide.