|
Hi Jon and Lorne - >I also pointers (and sometimes dynamic memory) with Multiple Occurrence >Data Structures because it gives me the ability to directly >compare/calculate/etc. between two or more occurrences. > >I also use pointers a lot when interacting with C functions (no choice but >to use them) but haven't found a use for linked lists lately. I haven't yet used dynamic memory allocation, but I recently wrote a program where I ended up using a doubly-link list in a MODS. I linked by the occurrence number, not using pointers. But I did end up using pointers to be able access multiple occurrences simultaneously, particularly since I needed to be able to update the data, so just making a copy wouldn't do. For Lorne, here are some code snippets. Here is the MODS. It is just a regular MODS, no pointers or dynamic memory allocation. It actually has a lot more fields than this. The contents is immaterial. d @detail ds 96 occurs(2000) d @areof n d @aivno# 7p 0 d @aivdt 7p 0 d @aoi@ 3p 0 d @aramt$ 9p 2 d @arpay$ 9p 2 d @ardiv# 1p 0 d @ariref 7p 0 Here is the data structure (not a MODS) that I want to be able to use as a particular occurrence of the MODS. It has the same definition but with different names, and is based on a pointer. The pointer definition follows the data structure definition. d @crddet ds 96 based(@crddet@) d @crd_areof n d @crd_aivno# 7p 0 d @crd_aivdt 7p 0 d @crd_aoi@ 3p 0 d @crd_aramt$ 9p 2 d @crd_arpay$ 9p 2 d @crd_ardiv# 1p 0 d @crd_ariref 7p 0 d @crddet@ s * I set the occurrence of @detail to the occurrence that I want to reference through @crddet. I then execute this code: c* c* Point the @crddet data structure to this occurrence c* c eval @crddet@ = %addr(@detail) I set the pointer to the address of the particular occurrence. Since the @crddet data structure is based on this pointer, it will continue to reference this occurrence of @detail, even after I set the occurrence of @detail to something else. This allows me to reference two occurrences of the data structure simultaneously. In this particular program I also had a @invdet data structure that I used the same way, so I was accessing three occurrences of the MODS simultaneously; one directly, using the current occurrence of @detail, and two indirectly using data structures based on pointers pointing to specific occurrences. Some of the fields in the MODS that I didn't copy into this message are the linked list fields, pointers to the next and previous elements in the list. Pointers in the generic sense; they are numeric fields containing the occurrence numbers of the next and previous occurrences. It could be done with actual pointer fields as well, but there was no reason to. Ken Southern Wine and Spirits of Nevada, Inc. Opinions expressed are my own and do not necessarily represent the views of my employer or anyone in their right mind. +--- | This is the RPG/400 Mailing List! | To submit a new message, send your mail to RPG400-L@midrange.com. | To subscribe to this list send email to RPG400-L-SUB@midrange.com. | To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com. | Questions should be directed to the list owner/operator: david@midrange.com +---
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.