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



Hi Mike,

But it seems both you and Scott are correct. What was running through my mind was the overhead of passing a buffer around. I thought a pointer might be more efficient.

All parameters (unless they're to a subprocedure and have the word "VALUE" on the prototype) are passed by reference. Passing something by reference means that the caller is sharing his memory with the program that he calls.

In other words, when you pass a parameter by reference, what you're REALLY doing is passing a pointer to that parameter. That pointer is used to share the memory between the two programs.

Since passing by reference is the only way to pass parameters to programs (as opposed to procedures) on the iSeries, there's no performance to be gained by passing a pointer instead of passing a data structure.

In fact, Paul's example that passes a pointer may not work the way you think it does. Although it does pass a pointer -- that pointer is passed by reference. So under the covers, it's really passing a pointer to a pointer. My example passes a pointer to the actual data, rather than a pointer to a pointer. So mine is marginally faster. (Though, frankly, you'll never notice the difference in a million years.)

The original question was therefore concerned with not passing the
entire record, but rather, having access to the fields by mapping the DS
in program B to the address reference provided by the pointer to avoid
passing a buffer which must have some sort of overhead.

But, it doesn't copy the buffer. ProgramA says "my parameter is in location 12345 in memory." and ProgramB says "okay, then I'll put my data structure in that area of memory". In other words, it's exactly the same thing as passing a pointer.

Except that it's more self-documenting.

And you do a better job of making it clear what needs to be passed.

And there's less chance of the caller making a mistake and corrupting memory.

I appreciate your explanation of the pointer situation in a multi-tier
call. It makes perfect sense. But then Scott's answer is probably
correct too as my situation is only a 2 tier call, as long as there is
little overhead.

My solution has LESS overhead.

Or am I being too paranoid about overhead? Of course, the parameter should be read only as all I'm doing is editing the values.

Then declare it as CONST on the prototype. (you can't do that with a pointer!) That way, the compiler will try to make sure you don't change the values.

Though, I'm baffled by why you'd want it to be read only if you're "just editing the values". Doesn't editing imply that you need to be able to change them?

It doesn't really matter, though.. you can do it either way.

As an Amazon Associate we earn from qualifying purchases.

This thread ...

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.