× 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.




I was thinking the opposite.  Since RPG compiler usually do this type of
things (you know auto initial alpha and numeric file, auto open
file....) for RPG programmer, I kind of except the compiler to know to
generate code to dealloc the memory automatically when the program set
the based pointer to *null.  Wishful think ... :)

Unfortunately, there's no way a compiler could do something like that. It'd have to be maintained by the operating system, which would have to monitor every use of every pointer.

For example, if you wanted the compiler to take care of it, then what about this?

     pointer1 = %alloc(1234);
     pointer2 = pointer1;
     pointer1 = *null;

Should that deallocate the memory when pointer1 is set to null? If so, what happens to pointer2? How could the compiler know that you're done with the memory?

It's tempting to think that the compiler should know that you set the value to pointer2, and it should deallocate it and set pointer2 to null as well. But that wouldn't work in all cases. Consider this example:

     pointer1 = %alloc(1234);
     pointer2 = my_subprocedure(pointer1);
     pointer1 = *null;

Now should the compiler know whether you're done with the memory and auto-deallocate it? What if my_subprocedure() isn't written in RPG, but is written in a completely different language that the compiler doesn't understand. How can it know whether the code in my_subprocdure() is still using the pointer? Plus, pointer2 may or may not be refering to the same memory...

If you want a method of clearing all leftover allocations, one exists... activation groups.

As an Amazon Associate we earn from qualifying purchases.

This thread ...

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.