× 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 learned this the hard way recently....

>>Now say you call:
>>       Proc1a('This is a Test':14);
>>       Proc1b('This is a Test');

>>I'm trying to understand the interactions between varying and *varsize
>>when the compiler builds the temporary variable due to the CONST.

>>Is the temporary for the call to Proc1a 32,768 bytes long or only 14? 
The "temporary" is 14 bytes long, however, since the procedure doesn't
really know what to expect.  it can (& will even unintentionally LOL)
access the full 32768a of memory!  Which of course means you can alter
memory you shouldn't be....(which was HOW I learned the hard way...)

>>How about Proc1b?
 (not exactly sure on this one...) I would *assume* that since you are
using a varying Const that the "temp" variable would be the size of the
string being passed.

>>Any difference when dealing with a string expression using
fixed-length
>>or varying strings?
>>       Proc1a('Fld1 is:' + fld1 : %len('Fld1 is:' + fld1));
>>      Proc1b('Fld1 is:' + fld1);
The biggest difference I think you'd see is in performance & really it
would depend on the size of the variable & many other factors.

>>Lastly, it is obvious that no temporary variables are needed when
Proc1a
>>calls Proc2. 
Why is it obvious?  The Proc2 doesn't know or care where the data comes
from, it will still act the same..


>>How about when Proc1b calls Proc2?  Am I going to get a
>>32768 byte temporary for that call or not? 
I believe you will get a temporary that is the size of the varying field
when the proc is called & the same gotchas mentioned above will still
apply.(not 100% sure on this one though...)



Thanks,
Tommy Holden


-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx
[mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Wilt, Charles
Sent: Friday, May 05, 2006 2:13 PM
To: RPG programming on the AS400 / iSeries
Subject: CONST Parameter passing, varying and *varsize

Ok,

I got a question about using varying and *varsize with CONST parameters.

First, let me make it clear that I do (mostly;-) understand the
differences between varying and *VARSIZE.

Now as to my question, perhaps an example would make it clear.

     d Proc1a          pr
     d  msgData                   32768a   const 
     d                                     options(*varsize)
     d  msgLen                       10u 0 const

     d Proc1b          pr
     d  msgData                   32768a   const 
     d                                     varying

     d Proc2           pr
     d  msgData                   32768a   const 
     d                                     options(*varsize)
     d  msgLen                       10u 0 const


Now the code for Proc1a and Proc2a

     p Proc1a          b
     d Proc1a          pi
     d  msgData                   32768a   const 
     d                                     options(*varsize)
     d  msgLen                       10u 0 const
      /free
         Proc2(msgData:msgLen);
         return;
      /end-free
     p Proc1a          e


     p Proc1b          b
     d Proc1b          pi
     d  msgData                   32768a   const 
     d                                     varying
      /free
         Proc2(msgData:%len(msgData));
         return;
     p Proc1b          e


Now say you call:
       Proc1a('This is a Test':14);
       Proc1b('This is a Test');

I'm trying to understand the interactions between varying and *varsize
when the compiler builds the temporary variable due to the CONST.

Is the temporary for the call to Proc1a 32,768 bytes long or only 14?

How about Proc1b?

Any difference when dealing with a string expression using fixed-length
or varying strings?
       Proc1a('Fld1 is:' + fld1 : %len('Fld1 is:' + fld1));
       Proc1b('Fld1 is:' + fld1);

What about just a varying field by itself?
       Proc1a(varyingFld1:%len(varyingFld1));
       Proc1b(varyingFld1);

I don't think the call to Proc1b would need a temporary variable or
would it?

Perhaps I should have Proc1b defined like so:
     d Proc1b          pr
     d  msgData                   32768a   const 
     d                                     varying options(*varsize)

That would give me a procedure that would accept any size varying field,
which is what I believe I want.  The question is, do I need varying and
*varsize to do what I want; which is minimize the size of any temporary
fields built.


Lastly, it is obvious that no temporary variables are needed when Proc1a
calls Proc2.  How about when Proc1b calls Proc2?  Am I going to get a
32768 byte temporary for that call or not?



Thanks,

Charles Wilt
--
iSeries Systems Administrator / Developer
Mitsubishi Electric Automotive America
ph: 513-573-4343
fax: 513-398-1121
 


As an Amazon Associate we earn from qualifying purchases.

This thread ...


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.