Tip

Ten important things to remember about heaps

Memory for dynamic variables is allocated off an internal structure called the "heap." The heap is simply a chunk of memory that the system allocates for an activation group when the activation group is created.

The Alloc, Dealloc, and Realloc op-codes are pretty straight-forward once you understand a few things about heaps.

  1. First, a heap is tied to, or scoped to, the activation group in which it was created. Each activation group has one heap called the default heap. The default heap is created automatically when the associated activation group is created. A program can also create additional heaps called user-created heaps using APIs.

  2. Heaps have an identifier. Since there can be multiple heaps in an activation group, heaps have an ID in order to uniquely identifier them. Many calls to dynamic memory management APIs require a heap identifier parameter to distinguish the heap on which the API is to act. The default heap in each activation group always has an identifier of 0 (zero).
  3. The RPG dynamic memory op-codes always operate on the default heap, so no identifier is necessary.
  4. Heaps are "owned" by the activation group in which they are created. When an activation group ends, all the heaps it owns are discarded.
  5. A heap's unique identifier is meaningful only within the activation group that owns the heap.
  6. Programs can manually create and discard additional heaps to satisfy unique storage requirements. User-created heaps can be created using the CEECRHP API and discarded with the CEEDSHP API. However, they can only be accessed using certain APIs.
  7. Heaps are created with a fixed size. The size is extended automatically to satisfy allocation requests.
  8. The maximum size for a heap is just under 4 GB provided there are not more than 128,000 individual allocations at a given time. The maximum size decreases in the off-chance the maximum number of allocations is exceeded.
  9. The maximum number of bytes for any allocation is limited to just under 16 MB.
  10. Programs in different activation groups can share the same heap. For example, a program can allocate a block of memory off it's default heap, then call another program that runs in a different activation group. If the first program passes a pointer to the allocated heap memory to the second program, the second program has full access to the heap in the activation in which the first program is running. It can access the memory as usual, and it can use the Realloc and Dealloc op-codes against it.

  11. This was first published in December 1999

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.