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 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.
- Functions that allocate public memory
- Duration keywords