Re: [OFFTOPIC] Re: C++ in kernel (was Re: exception in a device

Khimenko Victor (khim@sch57.msk.ru)
Thu, 14 Jan 1999 04:56:19 +0300 (MSK)


In <4.1.19990113172521.00c3d2a0@mail> Nate Tuck (nate.tuck@raycer.com) wrote:
NT> Since I've gotten so much entertainment value out of this "conversation" as
NT> a lurker, I feel compelled to give back to the greater community.

NT> At 04:01 AM 1/14/99 +0300, Khimenko Victor wrote:
>>Are you joking or just incompetent or may be just plain stupid ?

NT> All of us fall under one of these categories from time to time.

:-))

>>Since there are virtual calls in both C++ and C sample. C++ VIRTUAL CALL
>>requires one additional inevitable memory reference over C VIRTUAL CALL.
>>But looks like all your brain is wasted for C++ are no more room for any
>>new information.

NT> All your examples show is that inheritance in C++ is usually implemented
NT> with a pointer to a vtable, and that the compiler isn't quite smart enough
NT> to figure out that you only have 1 virtual function in your class and that
NT> it could replace the vtable ptr with the contents of the vtable ptr.

Not exactly. Real point is that in C++ you have non-optimal realization of
objects (it should be non-optimal since for different tasks optimal solution
is different :-) while in C you could make realization of YOUR (not compiler!)
choice ! Sometimes it's important, sometimes not so important. IMO kernel is
place where such flexibily is REALLY important...

NT> To turn your example on it's head, add another "virtual" function to your C
NT> and C++ code. Now count the number of cycles required to copy or
NT> initialize objects in a loop. Uh oh, looks like C is hopelessly broken, it
NT> requires an INEVITABLE extra memory reference.

INEVITABLE ? Are you joking ? Just add pointer to vtable and use one additional
memory reference (just like C++ :-). Here is the point: in C you have CHOICE
unlike C++ ! If you need fast call and not need fast copy or initialization
(like filesystem objects: there are exactly one object for each loaded
filesystem and thus speed of initialization is not matter even if there are
a lot of virtual functions; and copy is not allowed at all) you could have it.
If you need fast copy and not need fast call you could have this as well !
This is not so big deal for application programming but for kernel this is
real win...

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/