Start of Content Area

RfcEnvironment  Locate the document in its SAP Library structure

The RfcEnvironment function lets you supply your own routines for error handling and memory allocation:

void SAP_API RfcEnvironment(RFC_ENV * new_env);
typedef struct
{
void * (* allocate)( void * old_ptr, size_t new_size);
void (* errorhandler)( void);
}
RFC_ENV;

Supplying an Allocate Routine

If you specify an allocate routine (that is, the address is not NULL), RFC calls your routine (instead of the default one) whenever it allocates, resizes, or frees memory. Your allocate routine should be able to perform three operations:

allocate( NULL, size) /* to allocate memory */
allocate( address, 0) /* to free memory */
allocate( old_addr, new_size) /* to reallocate memory */

If you don't specify an allocation function, RFC uses the standard C library routines malloc, free, and realloc.

Supplying an Error Handler

If you supply an errorhandler function, it is always called when an error occurs within RFC.

Clearing the Environment Structure

You must clear the environment structure RFC_ENV when using the function RfcEnvironment. You can do this either implicitly:

static RFC_ENV rfcenv;
rfcenv.allocate =....;
RfcEnvironment( &rfcenv);

or explicitly:

RFC_ENV rfcenv;
memset( &rfcenv, 0, sizeof( rfcenv));
rfcenv.allocate =....;
RfcEnvironment( &rfcenv);

Either method maintains program flexibility, in case of future extensions to the RFC_ENV structure.