Good News Everybody!
The new search engine is LIVE!
Please report any problems to david (at) midrange.com.
|
Hi Joe,
> Unless I miss my guess, with a MODS or an array of structures, I have to
> predefine the number of entries. I use the technique shown whenever the
> size of the structure is known but the number of entries is not; it
> allows me to avoid having to specify the maximum number of entries the
> API can handle.
Unless I'm missing something, you had a predefined maximum number of
entries in your code sample. You called it "MAX" and told me to set it to
a suitably high number.
Here's the code you posted:
> d Entry e ds extname(myEntry)
> d based(p_Entry)
> d Entries s like(Entry) dim(MAX)
> d based(p_Entries)
> c eval pEntries = p_ListHeader + DataOff
> c for EntryNo = 1 to NumEntries
> c eval pEntry = %addr(Entries(EntryNo))
> (process entry)
> c endfor
>
> Set MAX to some reasonable maximum value, and voila, you should have no
> problems. (Famous last words!)
My response was, why not just replace the array that you called "Entries"
with an array of data structures (or a MODS if you're on V5R1 or earlier)
For example:
d Entries e ds extname(myEntry)
d based(pEntries)
d occurs(MAX)
c eval pEntries = p_ListHeader + DataOff
c for EntryNo = 1 to NumEntries
c eval %occur(Entries) = EntryNo
(process entry)
c endfor
It has the same limitation as your code... the MAX variable.
> I can write the called procedure to handle any arbitrary number of
> entries, but the actual number allocated depends on the calling
> application. It's a personal preference based on being bitten one too
> many times by fixed array sizes, while at the same time not wanting to
> create arrays with an arbitrarily large size.
For that, you should eliminate arrays altogether (including the "Entries"
array from your sample code) and do it purely with pointer logic, like I
did in the original code samples I posted when I started this thread.
> Well, I did say pretty specifically that the entries need to be a
> predefined size based on an external data structure. I couldn't tell
> from your example whether EntrySize was a variable or a constant.
Yeah, sorry... I should've been more explicit. I figured saying "List
APIs" was enough that you'd know that the entry size needs to be
soft-coded. I should've explained it better.
> If it were based on a data structure, it would be a pretty simple
> recompile for each release. But if you don't like that, well, do simple
> pointer arithmetic: pointer = header + offset + (entry-1) * size.
That logic was one of the samples that I posted.
> Or, if your size changes every time, then do this:
>
> EntrySize = 0;
> Pointer = header + offset;
> For x = 1 to numEntries
> Pointer = Pointer + EntrySize;
> (...)
> EntrySize = SizeOfCurrentEntry;
> Endfor
>
> There are several ways to do it without the nested if logic. Like I
> said, I just showed my little array magic as an example.
That's an interesting way to do it... set the entry size to 0 the first
time through, then set it to the real value at the end of the loop.
That's another good suggestion.
Thanks!
This mailing list archive is Copyright 1997-2026 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.