Home | Previous Page | Next Page   Design Decisions > Storing Data in Shared Memory >

Persistent User Data

The term user data refers to information that a purpose function saves in shared memory. The access method defines a user-data type and then allocates an area of memory with the appropriate size and duration. In the following example, the user data stores the information that the access method needs for a PER_STMT_EXEC duration.

Figure 4. Allocating User-Data Memory
MI_AM_TAB_DESC * tableDesc; /* Pointer to table descriptor */
typedef enum my_col_types
{
   MY_INT = 1,
   MY_CHAR
} my_col_type;

typedef struct my_row
{
   char           data[500];
   struct my_row *next;
} my_row_t;

typedef struct statement_data
{

   MI_DATUM   *retrow;   /*Points to data in memory*/
   my_col_type  col_type[10]; /*Data types in the projected row*/
   mi_boolean    is_null[10]; /*Array of true and false indicators*/
   my_row_t           *current row;
   MI_CONNECTION      *conn;
   MI_CALLBACK_HANDLE *error_cback;
} statement_data_t;

/*Allocate memory*/
my_data = (statement_data_t *) 
   mi_dalloc(sizeof(statement_data_t),PER_STMT_EXEC); 

mi_tab_setuserdata(tableDesc, (void *) my_data); /*Store pointer*/

Table 8 shows accessor functions that the VTI provides to store and retrieve user data.

Table 8. Storing and Retrieving User-Data Pointers
Descriptor User-Data Duration Stores Pointer to
User Data
Retrieves Pointer to
User Data
Table descriptor PER_STMT_EXEC mi_tab_setuserdata() mi_tab_userdata()
Scan descriptor PER COMMAND mi_scan_setuserdata() mi_scan_userdata()

The following example shows how to retrieve the pointer from the table descriptor that the mi_tab_setuserdata() function set in Figure 4:

my_data=(my_data_t *)mi_tab_userdata(tableDesc);

For more information about mi_tab_setuserdata(), mi_tab_userdata(), mi_scan_setuserdata(), and mi_scan_userdata(), refer to Descriptor Function Reference.

Home | [ Top of Page | Previous Page | Next Page | Contents | Index ]