POV-Ray : Newsgroups : povray.off-topic : Teach yourself C++ in 21 days : Re: Days 5- Server Time
29 Jul 2024 14:20:49 EDT (-0400)
  Re: Days 5-  
From: Invisible
Date: 17 Apr 2012 10:53:32
Message: <4f8d83ec$1@news.povray.org>
>> 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

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.