[LC++]OS Programming

Jan Reimers reimers at infoserve.net
Tue Oct 1 11:51:01 UTC 2002


On Wednesday 25 September 2002 09:36 pm, Paul Gearon wrote:
>
> In the case of Linux it's due to performance and size.  Polymorphism
> requires vtables, and vtables slow everything down considerably.

I often here this argument being made, but have you acually tested it for 
C++? The extra level of indirection is on the order of a few (2-4) clock 
cycles on modern processors, so unless your calling lots of virtual functions 
that don't do any processing you are unlikely to notice the effect of virtual 
dispach.

Also, polymoprhic function calls replace one of two things in non OO 
programming 1) an if/switch statment, 2) calling a function from an array of 
function pointers.  So there is no free lunch when the system design requires 
runtime decisions.

>
> C++ also naturally creates larger binaries. 

Yes absolutely, so for coding an OS you would have to make some rules like
1) No including <iostream>
2) Use a limited subset of the std. template conatiners
3) Be careful which functions are inline.
etc.

i.e. you use a subset of C++ that is suitable to your task.

I think the main reason OS's are still mostly written in C is the maturity of 
the standards and compiler technology.  Most notably there has only recently 
been a standardization of the C++ ABI, but nobody has implemented it yet.  
g++ is working towards that goal.

Cheers
Jan


> That's normally OK, because
> you can create much more complex and functional software because of the
> design benifits afforded you by using C++, and size and speed aren't
> normally an issue (buy bigger hardware if you have a problem).  However
> it's no good for an OS where size and speed DO matter.
>
> Regards,
> Paul Gearon
>
> Software Engineer                Telephone:   +61 7 3876 2188
> Plugged In Software              Fax:         +61 7 3876 4899
> http://www.PIsoftware.com        PGP Key available via finger
>
> Catapultam habeo. Nisi pecuniam omnem mihi dabis, ad caput tuum saxum
> immane mittam.
> (Translation from latin: "I have a catapult. Give me all the money,
> or I will fling an enormous rock at your head.")
>
>
> _______________________________________________
> This is the Linux C++ Programming List
>
> : http://lists.linux.org.au/listinfo/tuxcpprogramming List




More information about the tuxCPProgramming mailing list