Memory-duration options

When a UDR calls a DataBlade® API memory-allocation function, the memory exists until the duration assigned to that memory expires. The database server stores memory in pools by duration. By default, memory-allocation functions assign a PER_ROUTINE duration to memory. The database server automatically frees PER_ROUTINE memory after the UDR that allocates the memory completes.

An SQL statement typically invokes many UDRs to perform a table task. Memory that stores state information must persist across all the UDR calls that the statement requires. The default PER_ROUTINE duration does not allow memory to persist for an entire SQL statement.

Use the mi_dalloc() function to specify a memory duration for a particular new memory allocation. If you do not specify a duration, the default duration applies. You can change the default from PER_ROUTINE to a different duration with the mi_switch_mem_duration() function. The following list describes memory durations that an access method typically specifies:
  • Use PER_COMMAND for the memory that you allocate to scan-descriptor user data, which must persist from the am_beginscan through the am_endscan functions.
  • Use PER_STMT_EXEC or PER_STMT_PREP for the memory that you allocate for table-descriptor user data, which must persist from the am_open through the am_close functions.

You must store a pointer to the PER_COMMAND, PER_STMT_EXEC, or PER_STMT_PREP memory so that multiple UDRs that execute during the command or statement can retrieve and reference the pointer to access the memory.

For detailed information about the following, see the Informix® DataBlade API Programmer's Guide:
  • Functions that allocate public memory
  • Duration keywords