Dynamic Memory Allocation in Cobol

Asked

Viewed 388 times

2

How to allocate dynamic memory in Cobol without using external C libraries?

I have no interest in using some kind of *alloc() from C. In any flavor of Cobol exists? It must exist, because if some compilers now have access to databases, internet and POO, then they may. The English research didn’t help me much.

1 answer

4


The verb in COBOL that does this is ALLOCATE. Assignment of can only be used with a data item defined as BASED (which indicates that the compiler does not assign the usual storage for the data item). FREE release the unreached storage.

ALLOCATE / BASE / FREE have existed since the 2002 Standard which was replaced by the 2014 Standard. The implementation is down to the compiler vendor and not all compilers support this.

All Cobols will have additional ways to allocate storage assigned to a value of POINTER through a system call of some kind.

There is also a way to load, but not run, "a program" that contains the storage (usually for reference), using a PROCEDURE- POINTER (or a FUNCTION-POINTER).

CALL is used in many ways to do many things, including allowing access to storage outside the currently active program. If something doesn’t exist, you can always write a program and CALL it.

  • Hello and thank you for answering. Is there any sample code with all these commands? All these keywords? I have Stern & Stern but it seems to me he has nothing. Some Cobol books from the 80s are not a good choice. Is there a book that talks about this? I suppose internet examples are better. Thanks again.

  • Find the Gnucobol project (currently on Sourceforge ) . There are some examples there . Searching with keywords should also locate them. I contribute to this project. , And there is an active discussion area. Search Gnucobol Programming Guide by Gary Cutler .

Browser other questions tagged

You are not signed in. Login or sign up in order to post.