|
|
On 4/17/2012 7:17, Invisible wrote:
> would inlining it "bring its own performance costs"? I don't get that.
If you have several copies inlined different places, it may not be in CPU
cache (or might even be paged out). I.e., by inlining, if you make it
bigger, that's possibly a performance hit. Or not. Depends.
> OK, /that/ sounds rather more significant.
Not really.
> The book claims that if you write a function body inside a class definition,
> that makes the method inline. Is this true? I thought there was no
> difference either way...
It *has* to be. The reason it's inline if it's in a class definition is the
class definition gets compiled every time you #include it. Hence you're
going to have lots of copies of the same function compiled, which therefore
won't link, *unless* they're inline, because inline functions get merged by
the compiler, see.
*That* is why it's "significant".
> Even so, there might be 15^2 function calls, but only at most 15 of them
> will be /active/ simultaneously - which means only 15 stack frames at once. No?
Also, again, depends on your computer. I think we have 6 stack levels on the
credit card terminal available.
> Well, yes. As I understand it, by default C++ doesn't reserve a whole lot of
> stack space,
That's really nothing to do with C++ per se.
> I'm a curious soul. I think to have some idea how things work, even if I
> don't know all of the details... ;-)
It still depends on the compiler, the declaration, etc. "printf" isn't going
to pass any arguments in registers, most likely. abs() probably will. You
can declare (with pragmas, for example) different calling conventions for
different routines. (There is, for example, the Pascal calling convention,
which means the caller removes the arguments from the stack, because each
function in Pascal takes only a fixed number of arguments, so "remove them
from the stack" code logically can be in only one place.
--
Darren New, San Diego CA, USA (PST)
"Oh no! We're out of code juice!"
"Don't panic. There's beans and filters
in the cabinet."
Post a reply to this message
|
|