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



Larry Ducie wrote:
Also, as the return variable is aIways passed by value I would like to know
whether it is also subject to the low-level extra copy described by Barbara.
I know this was described as a low-level parameter passing function by the
OS, but I'd be interested to know if this applies to return variables too.
I'd also like to know if the passing of the return variable is subject to
the same casting/truncating/padding rules as parameters?

I just want to start by quoting Donald Knuth:
"We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil."

See http://en.wikipedia.org/wiki/Optimization_(computer_science)

It's worth reading the short section on "When to optimize" before reading any further here.

For VALUE vs CONST, choosing CONST over VALUE rarely impacts the design, so it seems reasonable to use CONST instead of VALUE as a general rule.

The same doesn't apply to return values, so it's important to bear Knuth's statement in mind when reading the rest of what I say here.

So ... yes, the issue with passing parameters by value does apply to return values too. If necessary, the compiler sets up temporary of the returned type, and then the OS works with the entire size of the returned value.

Unfortunately, there isn't such a good alternative as CONST vs VALUE. One alternative is to define your string-handling procedures to have the "returned value" passed by reference, and use the same LIKE type to define all such return values, and use the same LIKE type to define all string temporaries. Then it's not TOO bad to code like this:

D temp1 s like(string_t)
center (temp1 : title : 80);
result = temp1;

instead of the much nicer but possibly poorer performing
result = center (title : 80);

You could even provide two procedures each, where the one that returns a value calls through to the other one. Callers can then choose between convenience and performance, using the less convenient version when the performance of the other version is _has been determined to be a problem_.

Choose
result = center (val : len);
or
center_R (temp : val : len);
result = center;

D center b
D center pi like(string_t)
D val like(string_t) const
D len 10i 0 value
D result s like(string_t)
/free
center_R (result : val : len);
return result;
/end-free
D center e


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.