ALLOCATE ROW statement

Use the ALLOCATE ROW statement to allocate memory for a row variable. This statement is an extension to the ANSI/ISO standard for SQL. Use this statement with ESQL/C.

Syntax

ALLOCATE ROWvariable
Element Description Restrictions Syntax
variable Name of a typed or untyped row variable to allocate Must be an unallocated Informix® ESQL/C row-type host variable Language specific

Usage

The ALLOCATE ROW statement allocates memory for a host variable that stores row-type data. To create a row variable, an ESQL/C program must do the following:
  1. Declare the row variable. The row variable can be a typed or untyped row variable.
  2. Allocate memory for the row variable with the ALLOCATE ROW statement.
The following example shows how to allocate resources with the ALLOCATE ROW statement for the typed row variable, a_row:
EXEC SQL BEGIN DECLARE SECTION;
   row (a int, b int) a_row;
EXEC SQL END DECLARE SECTION;
. . .
EXEC SQL allocate row :a_row;

The ALLOCATE ROW statement sets SQLCODE (the contents of sqlca.sqlcode) to zero (0) if the memory allocation operation was successful, or to a negative error code if the allocation failed.

You must explicitly release memory with the DEALLOCATE ROW statement. Once you free the row variable with the DEALLOCATE ROW statement, you can reuse the row variable.
Tip: The ALLOCATE ROW statement allocates memory for the Informix® ESQL/C row variable only. To allocate memory for the Informix® ESQL/C collection variable, use the ALLOCATE COLLECTION statement.

When you use the same row variable in multiple function calls without deallocating it, a memory leak on the client computer results. Because there is no way to determine if a pointer is valid when it is passed, Informix® ESQL/C assumes that the pointer is not valid and assigns it to a new memory location.