Home | Previous Page | Next Page   Function Descriptions >

mi_zalloc( )

The mi_zalloc( ) function allocates and zero-fills a block of memory of the given size and returns a pointer to a block of user memory of the specified size.

Syntax

void *mi_zalloc (size)
   mi_integer size;
size
is the number of bytes to allocate and fill with zeroes.
Valid in Client LIBMI Application? Valid in User-Defined Routine?
Yes Yes

Usage

The mi_zalloc( ) function allocates size number of bytes of user memory for a DataBlade API module. The mi_zalloc( ) function behaves exactly like mi_alloc( ) except that mi_zalloc( ) fills the allocated block of memory with zeroes before the function returns the pointer to the memory. The mi_zalloc( ) function is a constructor function for user memory.

Server Only

The mi_zalloc( ) function allocates the memory in the current memory duration. By default, the current default duration is PER_ROUTINE. In C UDRs, the database server also automatically frees memory allocated with mi_zalloc( ) when an exception is raised.

Important:
Use DataBlade API memory-management functions, such as mi_zalloc( ), to allocate memory in C UDRs. Use of a DataBlade API memory-management function guarantees that the database server automatically frees the memory, especially in the cases of return values or exceptions, where the UDR would not otherwise be able to free the memory.
End of Server Only
Client Only

In client LIBMI applications, mi_zalloc( ) works exactly as malloc( ) does: it allocates storage on the heap of the client process. However, the database server does not perform any automatic garbage collection. Therefore, the client LIBMI application must use mi_free( ) to explicitly free all allocations that mi_zalloc( ) makes.

Important:
Client LIBMI applications ignore memory duration.

Client LIBMI applications can use either DataBlade API memory-management functions or system memory-management functions (such as malloc( )).

End of Client Only

The mi_zalloc( ) function returns a pointer to the newly allocated 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_zalloc( ) when that memory is no longer needed.

Return Values

A void pointer
is 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
indicates that the function was unable to allocate the memory.

The mi_zalloc( ) function does not throw an MI_Exception event when it encounters a runtime error. Therefore, it does not cause callbacks to be invoked.

Related Topics

See also the descriptions of mi_alloc( ), mi_dalloc( ), mi_free( ), and mi_switch_mem_duration( ).

For more information about memory allocation and memory durations, see the IBM Informix: DataBlade API Programmer's Guide.

Home | [ Top of Page | Previous Page | Next Page | Contents | Index ]