You are currently on IBM Systems Media’s archival website. Click here to view our new website.

Bookmark and Share

Recent Posts

Using the Debug Memory Manager With RPG

August 9, 2010

This blog was guest-written by Barbara Morris. Barbara is the lead developer for the RPG compiler in the IBM Toronto Lab. She has been working on the RPG compilers since she started at IBM in 1989 after receiving a Computing Science degree from the University of Alberta. Her first RPG enhancements for RPG/400 were ENDDO/ENDIF and *ON/*OFF. Her latest enhancement for ILE RPG is Open Access: RPG Edition. Thanks, Barbara!

RPG programmers who use RPG’s memory management operations (%ALLOC, %REALLOC and DEALLOC) should read Scott Hanson’s article about the debug memory manager. The debug memory manager can be used to locate errors in an application that uses heap storage. Debugging problems related to memory management can be very difficult because the symptom of the problem often occurs long after the problem was caused. I can attest from personal experience that the debug memory manager is a great tool. On one occasion it pinpointed my problem instantly. Without the debug memory manager, I would’ve had many repeated debug sessions, gradually working my way back to the original coding error that was causing the problem.

Unfortunately, by default, RPG programmers can’t take advantage of the debug memory manager. RPG’s memory-management operations use a different interface to heap storage than the one controlling whether the debug memory manager should be used.  RPG uses the CEEGTST, CEECZST, and CEEFRST APIs to handle memory-management operations in 6.1, and by default in 7.1. 

The good news is it’s possible for RPG programmers to take advantage of the debug memory manager by changing their RPG code. The change is simple in 7.1, and slightly more complex prior to 7.1.

In 7.1, RPG programmers can add keyword ALLOC(*TERASPACE) to the H spec of modules that use memory-management operations. Using that keyword will have two benefits. First, it will cause RPG to use the heap storage interfaces that have the option of using the debug memory manager. And second, it will allow RPG programmers to allocate much larger sizes of heap storage (up to 4,294,967,295 bytes versus the default maximum of 16,776,704 bytes).

Prior to 7.1, RPG programmers must call APIs instead of using RPG’s native memory-management operations. Instead of %ALLOC, call the _C_TS_malloc API. Instead of %REALLOC, call the _C_TS_realloc API. Instead of DEALLOC, call the _C_TS_free API.

Click here for an example that uses these APIs: Download I Can example 8.9.10

For more information about the ALLOC keyword, go here.

For more information about the memory management APIs, see the information for malloc(), realloc() and free().

Posted August 9, 2010| Permalink