As Adam ONeill noted in the SourceCode forum:
In fact, it is almost always going to be much more efficient to pass a UDT by reference. Passing by reference means that the compiler is passing a single 32-bit pointer, which takes up little space and can be accessed very quickly. Passing a UDT by value would mean putting every byte in the UDT on the stack, padding it as necessary for alignment and dword size (the stack has special requirements here). In general, this would be much slower and would consume more memory.
With a traditional "by value" approach, this problem would also affect strings. PowerBASIC finesses the issue: instead of "byval" causing the entire string to be passed on the stack, it makes a temporary copy of the original string, and passes the temporary copy by reference.
I agree that it would be nice to have a genuine BYVAL option for passing UDTs-- mostly for compatibility with outside products, in the odd event that they passed UDTs by value.
-------------
Tom Hanlin
PowerBASIC Staff
Also, this is not the place to ask, but why can't you pass a UDT with BYVAL, since it would speed things up a bit right?
With a traditional "by value" approach, this problem would also affect strings. PowerBASIC finesses the issue: instead of "byval" causing the entire string to be passed on the stack, it makes a temporary copy of the original string, and passes the temporary copy by reference.
I agree that it would be nice to have a genuine BYVAL option for passing UDTs-- mostly for compatibility with outside products, in the odd event that they passed UDTs by value.
-------------
Tom Hanlin
PowerBASIC Staff
Comment