Memory Allocation

Certain RAM functions, such as extractMember and getAllMemberInfo, require that the RAM allocate memory. This memory is later freed by CARMA, which uses C's free function to deallocate the memory. For this reason, a RAM implemented in COBOL must use C's malloc function or the Language Environment® service CEEGTST to allocate memory. The COBOL-to-C source has a C function called CMALLOC to provide access to malloc from within COBOL code. The CMALLOC function accepts as an argument an integer representing the requested number of bytes and returns a pointer to the portion of memory that was allocated. It is the RAM developer's responsibility to ensure that the pointer is not NULL before attempting to use the allocated memory.

The following sample call to CMALLOC illustrates its use:

01  MALLOC-SIZE                 PIC S9(9) BINARY.     
01  VOID-POINTER-RETURNED       POINTER.              
MOVE 80 TO MALLOC-SIZE.                               
CALL "CMALLOC" USING BY VALUE MALLOC-SIZE             
               RETURNING VOID-POINTER-RETURNED.       

The Language Environment callable service CEEGTST is also available for dynamically acquiring storage. For more information on this service and other services provided by Language Environment refer to z/OS® V1R9.0 Language Environment Programming Reference (SA22-7562-09).