The PER_ROUTINE memory duration
A PER_ROUTINE memory pool is associated with each routine invocation. A routine invocation is one single execution of a UDR within a routine instance.
When a C UDR allocates PER_ROUTINE memory, this memory is available to code within that single routine invocation of that UDR. The database server reclaims any PER_ROUTINE memory in the memory context when a single invocation of a UDR completes. This memory is actually freed on entry to the next routine invocation. The database server does not reclaim any memory in the memory context with a higher duration than PER_ROUTINE.
In a C UDR, the PER_ROUTINE memory duration is useful for information required for a single UDR invocation. A UDR cannot allocate memory, save a pointer to this memory in static space, and expect the pointer to be valid for the next routine invocation. To save information across invocations, use the user-state pointer of the MI_FPARAM structure. For more information, see Saving a user state.
Several DataBlade API constructor functions allocate their DataBlade API data type structure with a PER_ROUTINE memory duration. The following table shows the DataBlade API data type structures that have a memory duration of PER_ROUTINE.
DataBlade API data type structure | DataBlade API constructor function | DataBlade API destructor function |
---|---|---|
UDR arguments that are passed by reference | Routine manager (when it invokes a UDR) | Routine manager (when it exits a UDR) |
UDR return value that is passed by value | UDR with its declaration of its return value | Routine manager (when it exits a UDR) |
UDR return value that is passed by reference | UDR with call to mi_alloc(), mi_dalloc(), or mi_zalloc() | Routine manager (when it exits a UDR) |
The current memory duration is initialized to this default memory duration. The default memory duration is PER_ROUTINE. For more information, see Manage the memory duration.