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



Good point, Scott.  From everybody's posting, seems like there is really
no reason to ever set based pointer to *null by assigning *null to it.
If that is the case, I wonder if RPG compiler should as least throw an
error when such statement exist in the source code.  (Understanding that
there is no way for compiler to catch all cases as Scott has pointed
out).

 

-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx
[mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Scott Klement
Sent: Thursday, December 07, 2006 11:41 AM
To: RPG programming on the AS400 / iSeries
Subject: RE: dealloc (Correction)


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.
--
This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing
list To post a message email: RPG400-L@xxxxxxxxxxxx To subscribe,
unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives at
http://archive.midrange.com/rpg400-l.



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

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.