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



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.

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.