Saving user-state information in the first invocation of a UDR
About this task
To save user-state information in the first invocation of a UDR:
Procedure
- Use the mi_fp_funcstate() function to
retrieve the user-state pointer from the MI_FPARAM structure.
After the UDR has the user-state pointer, it can obtain state information from the private storage area on subsequent invocations.
- Check for a NULL-valued user-state pointer.
On the first invocation of your UDR, the user-state pointer is a NULL-valued pointer. If the user-state pointer is a NULL-valued pointer, allocate a private user-defined buffer or structure for the user-state information.
When you allocate memory for the user-state information, you must protect this memory so that it is not reclaimed while it is still in use. Define a memory duration of PER_COMMAND for this memory with a DataBlade® API memory-allocation function such as mi_dalloc() or mi_switch_mem_duration().
- Put the private data in the user-defined buffer or structure to initialize the user state.
- If the UDR has just allocated the private user-state buffer,
use the mi_fp_setfuncstate() function to store
the address of this user-defined buffer or structure as a user-state
pointer in the MI_FPARAM structure.
You save the user-state pointer in the MI_FPARAM structure so that later UDR invocations of the routine sequence can access the routine-state information.