During the AGR_INIT aggregation phase, a UDF must allocate the intermediate storage pointed to by FNC_Context_t.interim1.
To allocate the required memory, the UDF calls the FNC_DefMem library function, specifying the size of the structure, which has a 64000 byte maximum. The UDF cannot request more memory than the value of interim_size in the CLASS AGGREGATE clause of the CREATE FUNCTION statement. If interim_size is omitted, then the limit is 64 bytes.
For best performance, allocate only enough memory to satisfy the needs of the function for intermediate storage.
In the standard deviation function example, the size of the structure can be computed by using sizeof(AGR_Storage). The following statement allocates the intermediate storage pointed to by FNC_Context_t.interim1:
s1 = FNC_DefMem(sizeof(AGR_Storage));
- The aggregate function asks for more memory than the value of interim_size in the CLASS AGGREGATE clause of the CREATE FUNCTION statement
- The CLASS AGGREGATE clause of the CREATE FUNCTION statement does not specify a value for interim_size and the aggregate function asks for more than the default 64 bytes
- The function asks for more than the 64000 byte maximum
If the UDF cannot complete without the memory, then the function can return an error by setting up the SQLSTATE error results argument.