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



 >Anyway, Aaron, I thought you didn't do RPG anymore?  Didn't you say you
became a full time Java guy?

Did I say that? Well, maybe, in more or less words. . .

When RPG brings home the bacon then I make sure to have the fryin' pan ready
:-)  It's one of those cases where RPG was the right tool for the job even
though Java could have been used.

Aaron Bartell


-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx]
On Behalf Of Scott Klement
Sent: Thursday, October 20, 2005 6:06 PM
To: RPG programming on the AS400 / iSeries
Subject: RE: Find/Replace in IFS file - The fastest way to do it


> Hadn't thought of this!  So are you thinking I should read it into 
> something that can hold it (i.e. User space) or do some pointer 
> arithmetic on a string that has a base pointer?  I am thinking it 
> would probably be faster to do the pointer arithmetic.

I'd use the TS_malloc() API to allocate one piece of memory for the whole
thing. I'd use TS_malloc() instead of %alloc() because it allows you to
create an allocatation that exceeds 16mb.  I don't know if that's needed or
not.

The next problem will be doing the replaces.  It's relatively easy to search
a big area of memory, but much harder to replace the data efficiently.

The problem is "moving" all of the data that comes after the replacement
when the original length and the new length aren't the same.

For example, if you have  "Press the <enter> key"  and you make it say
"Press the <enter> key"  how would you do it?  You search for &lt;. 
When you find it, you replace it with "<"...  but since "<" is one character
and "&lt;" is 4 characters, you'll have 3 extra spaces after the <.  How do
you get rid of those spaces?  You copy the text"enter&gt; key" 
3 spaces to the left...  that eliminates the extra space.

Not a big deal with a string that short, it'll only take a second.

However, if you have megabytes of data, and you have to copy it over a few
spaces with every single find/replace operationg that you do, that'll add a
lot of processing time.

>> You might be able to whip up a nice search and replace function using
> memcpy and memcmp.

Also memchr().   You use memchr() to find the initial character in memory. 
Then you use memcmp() to see if it matches the whole string.  Then you use
memcpy() (or probbaly memmove()) to do the replace.

In my experiencing, using memchr() followed by memcmp() is much faster than
using memcmp() on every byte, or checking each byte individually using a
based field.  YMMV, of course.

Anyway, Aaron, I thought you didn't do RPG anymore?  Didn't you say you
became a full time Java guy?
--
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.