Until the activation group ends or the job ends all memory allocated within the job stays allocated until it is specifically deallocated. If your procedure allocates memory and does not deallocate it before the procedure ends (normally or abnormally) and the address of the allocation is not "saved"(1) then that memory can not be deallocated until the activation group or job ends.
(1) A static variable to hold the address or the address is returned to the caller.
Duane Christen
-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx
[mailto:rpg400-l-bounces@xxxxxxxxxxxx]On Behalf Of Kurt Anderson
Sent: Friday, September 19, 2008 1:20 PM
To: RPG programming on the AS400 / iSeries
Subject: RE: Dynamic Array as return/output parameter in export
procedure
Scott,
"the fact that the pointer itself is released doesn't really matter.
the value of the pointer is preserved, and that's what counts."
My confusion had to do with what automatic cleanup was doing. I was
thinking it would cleanup the value at an address, not just release the
pointer. Does automatic cleanup ever clear out the value at the
address? My knowledge of the behind the scenes memory management is
basic at best.
I appreciate you bringing this to my attention.
Thanks,
Kurt Anderson
Application Developer
Highsmith
-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx
[mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Scott Klement
Sent: Friday, September 19, 2008 10:12 AM
To: RPG programming on the AS400 / iSeries
Subject: Re: Dynamic Array as return/output parameter in export
procedure
Kurt Anderson wrote:
So myDynaArray_p is global? myDynaArray is local and not Static so it
would be cleaned up when the procedure ends. So the address of
myDynaArray_p would end up NULL right? Which would defeat the entire
purpose of the procedure.
myDynaArray is local -- but it's neither static nor automatic. It's
based on a pointer! RPG isn't going to manage it's storage for you!!
You have to manage it yourself.
so the labels "static" and "automatic" don't apply to based() data.
However, myDynaArray_p -- unless it's defined somewhere else that Lim
didn't show us -- is defined in automatic storage. So you're right that
the pointer itself will be reset to *NULL on subsequent calls. But, the
memory that it points to is not released -- just the pointer itself is.
Since the value that was in the pointer is passed back to the caller via
the piRtnListDynaArray parameter, the fact that the pointer itself is
released doesn't really matter. the value of the pointer is preserved,
and that's what counts.
It also doesn't matter that it's reset to *NULL, since the routine calls
%alloc() right away, anyway, which will provide a new address with new
storage.
So I guess I don't understand your concern, Kurt. What difference does
it make whether the pointer is in automatic or static storage?
If you got around that issue, I'd say that you'd also want to pass the
number of elements, otherwise the caller has no idea how many elements
there are to access and could attempt to access an elements beyond the
memory allocated.
On that score, I totally agree.
But would rather that he stop using this technique altogether :)
--
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.
--
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.
______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit
http://www.messagelabs.com/email
______________________________________________________________________
NOTICE: This electronic mail transmission may contain confidential information and is intended only for the person(s) named. Any use, copying, or disclosure by any other person is strictly prohibited. If you have received this transmission in error, please notify the sender via e-mail.
As an Amazon Associate we earn from qualifying purchases.