Not all "const" parameters are passed by "reference", right?
From: Ian Boyd (ian.borlandnews010_at_avatopia.com)
Date: 06/26/04
- Previous message: Dennis: "Cancellation of Tejas"
- Next in thread: Andrew Cruickshank: "Re: Not all "const" parameters are passed by "reference", right?"
- Reply: Andrew Cruickshank: "Re: Not all "const" parameters are passed by "reference", right?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 26 Jun 2004 17:17:34 -0400
It's been stuck in my head, a phrase that Mike Lische of TVirtualTree
mentioned once"
He said that it was wasteful and unnecessary to pass (for example) an
Integer as const. This is because the integer itself is 32-bits, and so
would the pointer pointing to that Integer. Both can be passed in registers
equally well - except that passing a 32-bit value by reference would incur
the extra cost of getting the address of the Integer.
After this had been nagging me for a year, i finally checked it. i wrote
both function, and compared the compiled operations. i wrote two function,
that take an Integer parameter; one const and the other not.
It looked to me (with my extremely limited experience with ASM) as though
Delphi didn't bother to get the address of the Integer variable. i.e. it did
the same operations both times.
So is it correct that the compiler is smart enough to not pass @variable,
when the varible itself is 32 bits? What if it's < 32 bits?
If it's not a performance penalty (however slight) i like having const on
"input" parameters - it helps the source be self-documenting, as well as
it's safety checks by the compiler that i'm not trying to modify something i
shouldn't.
p.s. Sorry if this is not the most appropriate group. Borland has a
newsgroup for every compiler, except Delphi.
- Previous message: Dennis: "Cancellation of Tejas"
- Next in thread: Andrew Cruickshank: "Re: Not all "const" parameters are passed by "reference", right?"
- Reply: Andrew Cruickshank: "Re: Not all "const" parameters are passed by "reference", right?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|