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



Scott,
The problem I have with this technique is that is _requires_ your input
string to be a VARYING field. It will not accept a traditional, fixed-length
field that does not include the VARYING keyword. So you end up having to
make a choice VARYING or NON-varying support for the function. 
I wish it would work without the need for CONST or VALUE but that is the
only way a VARYING parm will accept a non-VARYING field and vis versa. 

Bob Cozzi
Cozzi Consulting
www.rpgiv.com


-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx]
On Behalf Of Scott Klement
Sent: Tuesday, November 25, 2003 6:33 PM
To: RPG programming on the AS400 / iSeries
Subject: Re: Low performance on varying length field


> Independently of the number of bytes to be returned, the call of the
> procedure is very slow (time job running was 19 seconds). When I define
the
> return field like the input field with 255 bytes the call is faster
(runtime
> only 1 second).
>
> Why that? I would expect, that only characters needed and length
information
> are copied to the calling procedure. Not the hole storage area.

When returning a 64k string by VALUE, here's what your procedure has to
do:
    1) Address of input parameter is copied from caller to subproc.
    2) 65537 bytes of memory allocated for #RtnStr variable.
    3) up to 255 bytes of data are copied from $InpStr to #RtnStr
    4) 65537 bytes of data are copied from #RtnStr to the caller's #str1
    5) The memory allocated for #RtnStr is deallocated

The slowest point will be step 4, where the return value is copied, since
over 64k of data needs to be copied.

Instead, I would do it this way:

     P TSTPRC2         B
     D TSTPRC2         PI
     D   $InpStr                    255    varying const
     D   #RtnStr                  65535    varying options(*varsize)
     D   RtnStrSize                  10I 0 value

     c                   eval      RtnStrSize = RtnStrSize - 2

     c                   if        %len($InpStr) > RtnStrSize
     c                   eval      #RtnStr = %subst($InpStr:1:RtnStrSize)
     c                   else
     c                   eval      #RtnStr = $InpStr
     c                   endif

     c                   return
     P                 E

When you call it, do it like this:

     callp TSTPRC2(str2: str1: %size(str1))

Using this method allows you to use any size of data, just like your
solution did.

However, the only data that need to be copied back & forth is the ADDRESS
of the two strings (16 bytes each) plus the 4 bytes for the size.  Total of
36 bytes.

That should perform MUCH better than returning a 65537 byte variable.

Hope that helps...
_______________________________________________
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:
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.