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



 >Hmm, it seems there is a bug. 
Yep you are right.  Haven't had time to finesse the code yet, but thanks for
the reminder. I actually had code that did this in the past (made sure the
value I was search for didn't get stuck between two reads) but I can't seem
to find it now.  So if someone has it and wants to share that would be
great, otherwise I will just write it.

>I haven't had to build or locate a very speedy search and replace, but I
would investigate pulling the entire file into memory (assuming it will
always fit inside 16Mb), then write it out, translating by brute force. 

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.

>You might be able to whip up a nice search and replace function using
memcpy and memcmp.
How does memcmp fit into the mix for a solution? Are you thinking it would
work similar to a %scan? I haven't use this before so I am not challenging
you, I just don't know how you are applying it to the situation.

Aaron Bartell


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

On Thu, 2005-10-20 at 15:31 -0500, albartell wrote:
> Hi  y'all,
>  
> I am trying to find the fastest way to go through a text IFS file and 
> replace all occurrences of a string. The file sizes that I am working 
> with range from less then 200 bytes to over 80Kb. Obviously the 80Kb 
> one is causing the slowness problems that I want to try and remedy.
Hmm, it seems there is a bug.  If the data you are looking for crosses a
block boundary, your code is not catching it.  For example, assume the end
of a 60000 byte block looks like '&qu' and the beginning of the next block
is 'ot;', then you would not be replacing the &quot with the '"'.

>  
> Below is what I am doing essentially. It only takes two reads from the 
> IFS file to get all of the data, but I was wondering if there is any 
> way to do a find and replace faster on that large of a string (65535
varying)?
Your current routine scans the buffer six times.  Three of those (half!)
start with the same character.  If there isn't a '&', then some of the
searches could be avoided.

I haven't had to build or locate a very speedy search and replace, but I
would investigate pulling the entire file into memory (assuming it will
always fit inside 16Mb), then write it out, translating by brute force. 

If that's not fast enough, another possibility would be to investigate the
standard C library.  You might be able to whip up a nice search and replace
function using memcpy and memcmp.

"Algorithms in C" by Robert Sedgewick has some interesting string search
routines.

There are probably some MI functions as well.


Regards,
Rich

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