|
Thanks Scott. That should work. -----Original Message----- From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Scott Klement Sent: Tuesday, January 16, 2007 2:46 PM To: RPG programming on the AS400 / iSeries Subject: RE: Array * and big array
Yes, it is intentional. list.item will be used as a dynamic array. The basic idea is to allow caller to create multiple item lists. This
will be a service program and caller will do something like below to use it:
If list.item is to be a dynamic array, why not make THAT part of it use the pointer logic? After all, that's the part that requires a lot of space, not the outer array. If you make the item list dynamic, you eliminate the 64k limitation and you eliminate the 32k limit on the number of items in a list. Also, I'd only make the array accessible via subprocedures in a module, (I think that's what you intended to do, as well) and I'd put these procedures in a module by themselves to make sure nobody tries to access the array directly. That way, if you ever want to chenge the logic of how it works (for example, to switch to a linked list) you can do so without fear of breaking any of the callers. Unfortunately, I don't have time to test the following code -- I've written enough of these things that it should be reasonably close to being correct, but you'll have to do the testing yourself. I'm including it to give you a clearer idea of what I'm suggesting: D listMast ds qualified dim(512) D last 10i 0 inz(0) D alloc 10i 0 inz(0) D item * inz(*null) D item s 50a based(p_item) D ALLOC_BLOCK_SIZE... D C CONST(100) *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * addItem(): Add a new item on to the end of an item list * in the listMast() array. * * no = (input) listMast element number. * value = (input) value of the item to add *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ P addItem B export D addItem PI D no 10i 0 value D value 50a const D size s 10i 0 /free // ---------------------------------------------- // increase the number of items stored. // ---------------------------------------------- listMast(no).last = listMast(no).last + 1; // ---------------------------------------------- // expand array if necessary. // ---------------------------------------------- if (listMast(no).last > listMast(no).alloc); listMast(no).alloc += ALLOC_BLOCK_SIZE; size = %size(item) * listMast(no).alloc; if (listMast(no).item = *null); listMast(no).item = %alloc(size); else; listMast(no).item = %realloc(listMast(no).Item: size); endif; endif; // ---------------------------------------------- // store new value. // ---------------------------------------------- p_item = listMast(no).item + %size(item) * (listMast(no).last-1); item = value; /end-free P E *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * getItem(): Retrieve an item's value from the listmaster *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ P getItem B export D getItem PI 50a D no 10i 0 value D elem 10i 0 value /free if (elem < 1 or elem > listMast(no).last); return *blanks; endif; p_item = listMast(no).item + %size(item) * (elem-1); return item; /end-free P E *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * setItem(): Update an item's value from the listmaster *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ P setItem B export D setItem PI 1n D no 10i 0 value D elem 10i 0 value D value 50a const /free if (elem < 1 or elem > listMast(no).last); return *off; endif; p_item = listMast(no).item + %size(item) * (elem-1); item = value; return *on; /end-free P E *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ * freeList(): Free up all memory used by the list *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ P freeList B export D freeList PI D x s 10i 0 D p s * /free for x = 1 to %elem(listMast); p = listMast(x).item; if ( p <> *null ); dealloc p; listMast(x).item = *null; listMast(x).last = 0; listMast(x).alloc = 0; endif; endfor; /end-free P E Hope that makes sense. It allows for up to 16mb in each item list, and the amount of memory that each uses is only expanded when needed. The code is pretty easy to follow (for pointer logic) once you understand what it's doing. -- 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 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.