POV-Ray : Newsgroups : povray.off-topic : Teach yourself C++ in 21 days : Re: Days 5- Server Time
29 Jul 2024 22:27:38 EDT (-0400)
  Re: Days 5-  
From: Darren New
Date: 19 Apr 2012 21:14:05
Message: <4f90b85d$1@news.povray.org>
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

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