Mail Archives: djgpp/2000/01/02/07:56:09
On 2 Jan 00, at 1:00, sl wrote:
>
> On Fri, 31 Dec 1999 22:23:18 +0600, Kalum Somaratna aka Grendel wrote:
>
> >I think what you should do is that you should move your say
> >plotpixel and other inlined fuctions to header files.
>
> The problem is that in C++, this gets VERY ugly when you stick the
> implementation of a member function in the middle of a class. I insist of
> leaving all implementation in the .cc file..
>
In C++ AFAIK the whole point of putting a member func body in the
class definition is to ask for it to be inlined when it's called.
Actually Gilli, When you normally call a function from another
module which has it's source in a .cc or .c(ie-: source file) the
compiler will have to generate additional code to setup the stack
(push ebp etc) and also call your function. Since this can be quite
wastefull if the function is heavily called inlining will help to
eliminate the overhead but from my experience the compiler must
be able to see the code for the function being called (putpixel func)
and the source file it's been called from (test.cc for ex), at the
sametime.
So if you have the putpixel in a header file (graphics.h) with it's full
function body and it's been called by a source called test.cc then
when you call the putpixel routine from the test.cc file, the compiler
has already read the graphics.h file and knows the complete code
for the putpixel functions so it doen't need to setup the stack and
push and pop all those things, it directly substitutes the functions
code where the function call should have occured (this will increase
your code size a bit).
So AFAIK for inlining to work the compiler must have access to the
functions body (code) at the point when the func is been called.
Actually Gilli, about your comment on the very ugly aspect of
sticking a member func in the class definition, When you do that
the function can automatically be inlined by the compiler. And I
also don't think that it's ugly, I've seen a lot of code with it.
For ex-:
//file graphics.h
Class draw{
draw();
void put_pixel(int x,int y)
{
//drawing code
}
}
When the graphics.h header file is included the put_pixel will be
automatically inlined (no need to specify inline) by the compiler
(That's the whole point of putting the member func in the header,
You are asking for a inline without the overhead of a func call).
Hope This helped You,
Kalum
- Raw text -