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 an index 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_STATEMENT 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 or PER_STATEMENT 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