SQL Programming Manual for TAL
Dynamic NonStop SQL Operations
HP NonStop SQL Programming Manual for TAL—527887-001
7-19
Dynamically Allocating Memory
To allocate memory for the names buffer, you call GETPOOL using the saved value
from sqlsa.PREPARE.INPUT^NAMES^LEN. In this call, INAMESBUF^PTR is a pointer
to the memory allocated for an input names buffer.
IF inameslen > 0 THEN
@inamesbuf^ptr := GETPOOL(pool^head, $DBL(inameslen) );
Figure 7-2. Allocating the SQLDA Structure
* $LEN(sqlda^mem.sqlvar);
INT num^entries;
-- variables
-- number of input or output
-- return the pointer to newly allocated memory:
return @sqlda^ptr;
END;
-- If you are not handling null values, initialize IND^PTR
-- to null (code shown earlier in this section)
-- Initialize EYE^CATCHER (code shown earlier)
mem^reqd := $LEN(sqlda^mem) + (num^entries - 1)
-- call GETPOOL to allocate memory (error checking omitted)
@sqlda^ptr := GET (pool^head, $DBL(mem^reqd) );
sqlda^ptr.num^entries := num^entries;
-- Compute amount of memory needed for the SQLDA. Formula
-- used here is recommended. sqlda^mem is explained
-- earlier in this section.
BEGIN
INT i; -- loop counter
INT mem^reqd; -- number of bytes -- required for
-- the SQLDA
INT .EXT sqlda^ptr(sqlda^type);
-- returned
-- pointer to be
-- SQLDA^TYPE and SQLVAR were generated by INCLUDE SQLDA
INT(32) PROC allocate^sqlda (num^entries);
-- Pool must be initialized using DEFINEPOOL before this
-- procedure is called
-- LITERAL pool^size^in^bytes = 8192d;
-- INT .pool^head[0:18];
-- INT .pool[0:pool^size^in^bytes/2d - 1d];
VST0702.vsd