COBOL Manual for TNS/E Programs (H06.08+, J06.03+)
• Compatible with malloc() function
The ALLOCATE statement is compatible with the C Run-Time Library function malloc() and
related functions. To release the memory, a non-NULL pointer returned by ALLOCATE can be
passed to a C-language routine that calls free().
• Cannot be checkpointed
Dynamic memory cannot be checkpointed to a backup process.
ALLOCATE Memory for a BASED Item
ALLOCATE with a BASED item allocates dynamic memory for the BASED item. The size of the
memory allocated is derived from the size of the item.
based-name
is a level-01 or level-77 BASED data item. The number of bytes of memory to allocate is the
size of the data item described by based-name. If the item is a record containing an OCCURS
DEPENDING ON clause, the maximum size is used. The implicit pointer associated with
based-name is set to the address of the allocated memory.
pointer
is a data item described as USAGE POINTER. pointer is set to the address of the allocated
memory.
Usage Considerations:
• Use only when the STANDARD 2002 directive is in effect.
• With pointer specified
If you specify pointer, the pointer item is set to the address of the allocated memory, and
then the implicit pointer associated with based-name is set to the same address.
• Sufficient memory is not available
If sufficient memory is not available, pointer (if specified) and the implicit pointer associated
with based-name are set to NULL, and execution continues.
• INITIALIZED specified
The optional INITIALIZED phrase causes the allocated memory to be initialized. If based-name
describes an elementary data item, it is initialized according to one of the following rules. If
based-name describes a record, each elementary subordinate item is initialized according
to one of the following rules. The first rule that applies is the rule that is used.
◦ If the item has a VALUE clause, it is initialized to the specified value.
◦ If the item is described as USAGE POINTER, it is initialized to NULL.
◦ If neither of the preceding apply, the item is initialized according to the rules for the
INITIALIZE statement with no REPLACING phrase, except that FILLER items are also
initialized.
290 Procedure Division Verbs










