Choose memory duration
When the UDR allocates memory, it must ensure that this memory has a appropriate memory duration. Choose a memory duration on the basis of which UDR instances need to share the information stored in the memory. Make sure you choose a memory duration that is appropriate to the use of the allocated memory.
- If you allocate memory with a duration that is too small, expect
to see assertion failures in the message log file.
For example, if you allocate PER_ROUTINE memory and store its address in the MI_FPARAM structure (which has a PER_COMMAND duration), the memory is freed after one invocation of the UDR, causing the address in the MI_FPARAM to be no longer valid.
- If you allocate memory with a duration that is too large, you
might see memory leaks as your UDR executes.
Memory leakage can occur when you allocate memory that has a higher duration than the structure that holds its address. For more information, see Monitor shared memory.
- Public memory-management functions
- mi_alloc()
- mi_dalloc()
- mi_zalloc()
- mi_free()
- mi_switch_mem_duration()
- mi_realloc()
These public functions are appropriate for a UDR that executes in the context of just one SQL statement. The current memory duration, which these functions use, is a useful way to ensure that all allocations occur with the same duration. For more information, see Manage the memory duration.
- Public memory durations
- PER_ROUTINE
- PER_COMMAND
- PER_STMT_EXEC
- PER_STMT_PREP
For more information, see Public memory durations. Advanced memory durations are necessary only in certain situations.