× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Maybe it was implied or maybe I missed it, but nobody mentioned memory leaks (a phrase which refers to allocating memory but failing to deallocating it when finished with it). IIRC there is a maximum size of the heap space in an activation group of 16 mb. The original poster is no doubt already aware of the danger, but I just wanted to add my $0.02 and say that care should be taken to minimize the danger of overflowing the heap. If a program is looping and allocating storage each time, but through some bug or oversight isn't deallocating it, then at a certain point the system won't let them allocate any more and the only way to get that leaked memory back is to reclaim the activation group.

Barbara Morris wrote:
Rory Hewitt wrote:
...
Hence, it's ALWAYS a good idea to use the N extender to the DEALLOC op-code.
That way, you'll pick up any of these errors in testing, because your
program will throw an error. Frankly I don't know why IBM didn't make the
N-extender the default - backwards-compatibility, I assume.


Backwards compatibility wasn't an issue when DEALLOC was first invented.

I agree that it's always a good idea to use (N).

If I recall correctly (and I should, since this was my doing), the
reason for not always setting the dealloc'd pointer to null was to try
to force RPG programmers to be a conscious of the need for clearing the
pointer after deallocation.  If it was always just that one pointer
variable that had the address of the allocated storage, there would be
no issue, but a programmer should be aware of any other variables that
should also be cleared.
    p = %alloc(len);
    save_p = p;
    ...
    p = p + offset;
    ...
    dealloc(n) save_p;
    // p is now pointing to illegal storage but the compiler has no way
to know that
    // or rather, the compiler isn't nearly smart enough to know that

I have seen dealloc(n) coded in many real RPG programs, so clearly some
RPG programmers are conscious of it.  I suspect the set of RPG
programmers that codes (N) is the same set that would know to clear the
pointer anyway.  But maybe, just maybe, some other programmers have seen
the (N) when reading or copying code, and have learned something from
it.

In hindsight, I think it would probably have been better just to always
clear it, to take care of 99.9% of the opportunities for error.


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.