Uumm. I'm kind of surprise to hear you say that you don't see any value
of specifying (n). Then, again, you are very familiar with pointer
stuffs.
The code below will actually run (No runtime error), (Yes, I know I
should not be doing this :)
D myField s 100 based(myField_p)
/free
myField_p = %alloc(%size(myField));
myField = 'TEST';
dealloc myField_p;
myField = 'TEST';
*inlr = *on;
/end-free
However, if I use (n), at run time it will fail when it executes the 2nd
myField = 'TEST'
D myField s 100 based(myField_p)
/free
myField_p = %alloc(%size(myField));
myField = 'TEST';
dealloc(n) myField_p;
myField = 'TEST';
*inlr = *on;
/end-free
For me, it looks like (n) is a safer choice.
-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx
[mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Scott Klement
Sent: Friday, February 15, 2008 12:44 PM
To: RPG programming on the AS400 / iSeries
Subject: Re: dealloc vs dealloc(n)
Hello Lim,
is there a reason to ever use dealloc without the (n) extender?
When dealloc was first introduced into the RPG language, it didn't have
an (N) extender... if you want to support older releases, you'll have
to omit the (N) indicator. (Sorry, I can't remember which release (N)
was introduced in.)
Personally, I've never seen any value in specifying (N). I guess you'd
use that to verify that your code doesn't accidentally reference memory
that has been deallocated -- but keep in mind that (N) only sets the
pointer you give in the result field to *NULL. It doesn't set any other
pointers you've used in your code, so they might still reference the
deallocated memory. Furthermore, I tend to encapsulate pointer logic
into procedures, and in that scenario, the "free" (or "deallocate")
procedure tends to receive the pointer by value -- therefore, setting it
to null serves no purpose.
So I'm hard-pressed to find much value to the (N) extender. Granted, it
doesn't hurt anything -- but it rarely provides any value for me.
--
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.