|
> I've decided to try and tackle userspaces to see if it will speed up my > monster IFS posting job. i've got a pretty good idea what I'm doing, but > i'm fuzzy on scanning the space once i've loaded it. > Huh? I don't understand... you're reading it from one stream-formatted object, and writing it to another. Then, you've got to scan the second object and read records out of it? This is going to improve performance?! I'm completely lost. Why would you want to do this? > C if $FD <> *null > * get size of file using stat() > * (add a 100 bytes for safety) > c eval statsize = %size(statds) > c alloc statsize p_statDS > c eval $filesize = st_size + 100 > c dealloc p_statDS I'm not sure I understand why you're adding 100 here. Are you going to use that for some of your own data? Your comment says it's for "safety"?! > C eval rdlen=read($FD:USPtr:$fileSize) > > > I understand the concept of pointer math. to scan the data for each > record, do I now have to define a string in my program based (at first > anyway) on USPtr, with a length of what I think the maximum record length > could be, and then scan that field for end of record to give me a beginning > and end of the data I want to process? and then once processed, I just add > that length to my pointer (+1) to start my scan for the next record? I suppose you could do that. You'd probably have to use memchr() to scan for the x'0A'.... that's what I'd do, if I had to. > can that based string somehow be varying? I don't see how. If you made it varying, you'd have to manually set the length, which would in turn overwrite part of your user space data. > is there another way to scan the userspace in-line without basing a > variable to a pointer somewhere in the userspace? I would use the C functions memchr() and maybe also memcmp(). You only need memcmp() if you're looking for more than one character. Heres a function I wrote to search & replace a large buffer, such as a user space. It uses memchr() and memcmp() to do the search for the words to replace... It's not exactly what you're looking for, but should give you the pieces that you need in order to write your own record searching routine... *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * Search a buffer for a string & replace with another string * * Note: We can't use the RPG %scan & %replace BIFs because * there's no way to specify a pointer & size to search, * they work strictly on RPG variables. * * peBuf = buffer to search * peSize = size of buffer to search * peString = string to search buffer for * peToString = string to insert when peString is found. * * Returns the number of times the string was replaced *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ P ReplaceString b D ReplaceString PI 10I 0 D peBuf * value D peSize 10I 0 value d peString 32A value varying D peToString 32A value varying D memchr PR * extproc('memchr') D buf * value D chartofind 10I 0 value D bufsize 10I 0 value D memcmp PR 10I 0 extproc('memcmp') D buf1 * value D buf2 * value D size 10I 0 value D memcpy PR * extproc('memcpy') D dest * value D src * value D size 10I 0 value D dsCh DS D dsCh1 1A D dsCh2 3U 0 overlay(dsCh1) D p_found s * D wwAdvance s 10I 0 D wwReps s 10I 0 c eval wwReps = 0 c eval dsCh1 = %subst(peString:1:1) c dow 1 = 1 c eval p_found = memchr(peBuf: dsCh2: peSize) c if p_found = *NULL c leave c endif c if memcmp(p_found: %addr(peString)+2: c %len(peString)) = 0 c callp memcpy(p_found: %addr(peToString)+2: c %len(peToString)) c eval wwReps = wwReps + 1 c eval wwAdvance = (p_found - peBuf) + c %len(peToString) c else c eval wwAdvance = (p_found - peBuf) + 1 c endif c eval peBuf = peBuf + wwAdvance c eval peSize = peSize - wwAdvance c enddo c return wwReps P E > > does this make sense? I don't have a problem writeing this thing based on > what I've described above, but it just seems, oh, not very flexible - > having to define a maximum record length and all. > > keep in mind, i'm writing this for processing speed, not for convenience. My guess is that it will not perform as well as fopen() fgets(), etc. Unless, of course, you're planning to read the whole thing multiple times? I assume you're going to benchmark both routines? please share your results. > > Oh, and one more thing: does a userspace created in QTEMP work the same as > any other object in QTEMP? (i.e. each job can have it's own copy of the > same named usrspc.) > Yes... of course... it's just an object in QTEMP, like any other.
As an Amazon Associate we earn from qualifying purchases.
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.