|
![](/i/fill.gif) |
>> why would inlining it "bring its own performance costs"? I don't get that.
>
> In fact, inlining can actually sometimes reduce the size of the executable
> (because a function call may be replaced with an expression that gets
> calculated at compile time and optimized away).
That's what I figured.
>> 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...
>
> A function definition inside a class definition is implicitly 'inline'
> (without having to explicitly use the keyword; you could specify it, but
> it would be redundant.)
Hmm, OK. So is it a good idea to include simple accessor methods in a
header file then? (The book seems to suggest it is.)
> Likewise template functions are implicitly 'inline' without having to
> explicitly say so.
Well, by definition a template generates a new copy of the function each
time you use it, no?
>> 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?
>
> You may be right.
I usually am. :^)
>> Well, yes. As I understand it, by default C++ doesn't reserve a whole
>> lot of stack space, so you're likely to overflow it quite quickly.
>
> It depends on the OS. (In most unixes you can actually set how much
> stack is given to a process.)
Yeah, I should think most times you can throw a compiler switch, or ask
the OS to reserve more at run-time.
PS. I can't believe I just wrote "I usually am". Heh.
Post a reply to this message
|
![](/i/fill.gif) |