1. Josef Koláček
  2. PowerBuilder
  3. Sunday, 12 March 2023 09:12 AM UTC

Hello Appeon Community,

 

According to article from https://docs.appeon.com/pb2019/pbug/ch07s02.html#ug12761:

Read-only. When you pass as read-only, the variable's value is available to the function but it is treated as a constant. Read-only provides a performance advantage over passing by value for string, blob, date, time, and datetime arguments, because it does not create a copy of the data.

 

I am just wondering, is there a performance advantage also for standard numeric datatypes (int, long) when passed by readonly? If not, why?

 

Thank you in advance,

Josef

Accepted Answer
John Fauss Accepted Answer Pending Moderation
  1. Sunday, 12 March 2023 17:49 PM UTC
  2. PowerBuilder
  3. # Permalink

When an argument is passed by value, the value itself is placed on the argument stack by the calling code and removed from the stack by the called method. As Roland points out, numeric values in memory occupy a small number of bytes, many in four bytes or less, with some taking more than that.

When an argument is passed read-only or by reference, the value's memory address is passed on the stack, which will be either four bytes or eight bytes, depending on whether the app runs as 32-bit or 64-bit.

Since roughly the same number of bytes is being passed, on average, for numeric values versus read-only/by reference, there is no discernible speed advantage in the actually transfer of the information. When an argument is passed by value, the value has to be popped from the stack and copied to a local memory location, but when an argument is passed read-only or by reference, the address itself has to be popped and placed into local memory, so it's not really very different.

When CPU's are so incredibly quick as they are today, any difference in overhead for numerics is a proverbial drop in the bucket.

Comment
There are no comments made yet.
Roland Smith Accepted Answer Pending Moderation
  1. Sunday, 12 March 2023 15:10 PM UTC
  2. PowerBuilder
  3. # 1

Since a number will have less than 10 bytes, there won't be a speed advantage over by value. The speed advantage comes when passing large strings or blobs.

Comment
  1. Chris Pollach @Appeon
  2. Sunday, 12 March 2023 15:26 PM UTC
Unless, your calling the method 100's of times in a tight loop. ;-)
  1. Helpful 1
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Sunday, 12 March 2023 10:08 AM UTC
  2. PowerBuilder
  3. # 2

Hi,

As far as I've understood, passing as "readonly" is using a pointer (therefore no copy), but without the possibility of modifying.

Correctme if I'm wrong.

regards

Comment
  1. Josef Koláček
  2. Sunday, 12 March 2023 11:43 AM UTC
Thanks for your response, that's what I think as well.

Nevertheless, the documentation only mentions those 5 standard data types, not all. Hopefully I (we) will find out soon :)
  1. Helpful
  1. Miguel Leeuwe
  2. Sunday, 12 March 2023 13:12 PM UTC
Anything that's an object, is passed by reference, regardless of what you specify. (I think I read that somewhere).
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.