[fpc-devel] Question on constref
Michael Van Canneyt
michael at freepascal.org
Wed Feb 1 14:27:10 CET 2023
On Wed, 1 Feb 2023, Hairy Pixels via fpc-devel wrote:
>
>
>> On Feb 1, 2023, at 8:16 PM, Adriaan van Os via fpc-devel <fpc-devel at lists.freepascal.org> wrote:
>>
>> Because, if e.g. the byte-size of a parameter is such that it fits into a CPU register, then passing the parameter itself is more efficient than passing a reference to it. For large byte-size parameters, const and constref function the same. The difference is with small byte-size parameters.
>
> Hmmm I was told otherwise by one of the compiler devs and that I should use constref if I want to guarantee it will not be copied. Maybe one of them can confirm this….
That's exactly what Adriaan is saying. With const the compiler can choose.
With constref, you force it not to copy. But this is not so efficient for
small parameter sizes.
Michael.
More information about the fpc-devel
mailing list