The mi_dalloc() function
The mi_dalloc() function allocates the specified amount of memory for the specified memory duration and returns a pointer to the allocated block.
Syntax
void *mi_dalloc (size, duration)
mi_integer size;
MI_MEMORY_DURATION duration;
- size
- The number of bytes to allocate.
- duration
- A value that specifies the memory duration of the user memory
to allocate. Valid values for duration follow:
- PER_ROUTINE
- For the duration of one iteration of the UDR
- PER_COMMAND
- For the duration of the execution of the current subquery
- PER_STATEMENT (Deprecated)
- For the duration of the current SQL statement
- PER_STMT_EXEC
- For the duration of the execution of the current SQL statement
- PER_STMT_PREP
- For the duration of the current prepared SQL statement
- PER_TRANSACTION (Advanced)
- For the duration of one transaction
- PER_SESSION (Advanced)
- For the duration of the current client session
- PER_SYSTEM (Advanced)
- For the duration of the database server execution
Valid in client LIBMI application? | Valid in user-defined routine? |
---|---|
Yes (however, the application ignores memory duration) | Yes |
Usage
The mi_dalloc() function allocates size number of bytes of shared memory with duration memory duration for a DataBlade® API module. The mi_dalloc() function is a constructor function for user memory. This function behaves exactly like mi_alloc() except that mi_dalloc() enables you to specify the memory duration explicitly at allocation time.
- PER_ROUTINE (or PER_FUNCTION)
If you specify PER_ROUTINE, the database server frees the allocated memory when the UDR returns.
- PER_COMMAND
If you specify PER_COMMAND, the database server frees memory when the execution of a subquery is complete.
- PER_STMT_EXEC
If you specify PER_STMT_EXEC, the database server frees memory when the execution of an SQL statement is complete.
- PER_STMT_PREP
If you specify PER_STMT_PREP, the database server frees memory when a prepared SQL statement terminates.
A UDR can use mi_free() to free memory allocated by mi_dalloc() explicitly when that memory is no longer needed.
Client LIBMI applications ignore memory duration.
Within a callback function, a call to mi_dalloc() that requests a duration of PER_COMMAND returns NULL. Therefore, a callback function must call mi_dalloc() with a duration of PER_ROUTINE.
The mi_dalloc() 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.
For more information about memory allocation and memory duration, see the HCL OneDB™ DataBlade API Programmer's Guide.
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_dalloc() function does not throw an MI_Exception event when it encounters a runtime error. Therefore, the function does not cause callbacks to be invoked.