Re: c++
Re: c++
- Subject: Re: c++
- From: Brian Willoughby <email@hidden>
- Date: Wed, 11 Feb 2009 10:48:05 -0800
On Feb 11, 2009, at 07:46, Jens Alfke wrote:
On Feb 11, 2009, at 4:55 AM, Joel Reymont wrote:
All of the CoreAudio example code seems to be written in C++.
I assume that CoreAudio itself is written in C++ too.
Is there a particular reason for this? Why not C or Objective-C?
Not C, because they wanted to use object-oriented programming, I
presume. (I agree. I would never want to write anything in pure C
again.)
Not Objective-C, because CoreAudio is pretty low down in the OS
stack and has to run in contexts where you don't necessarily want
the overhead of the Obj-C runtime or the Foundation framework. Also,
Obj-C method dispatch is slightly slower than C++, and that can be
significant in highly optimized real-time code. And also^2, the
hardware-interface parts of CoreAudio tie into IOKit, which has a C+
+ API.
This is not true. It is a myth that the ObjC dispatch is slow. Apple
showed as far back as WWDC 2001 that the call dispatch measured in
ix86 cycles is actually slower than the ObjC method invocation on
ppc. Not sure whether they showed a comparison of x86 C++ to x86 ObjC
in those days, since it had been a while since Apple shipped Mac OS X
for Intel. But, believe me, the ObjC run time is highly optimized and
uses caching.
Another case in point is that NeXT based all of their kernel device
driver code on ObjC, even audio device drivers. If the ObjC run time
is fast enough for an audio device driver, then it is certainly fast
enough for an audio API. I'm talking about the days when computers
were running in the sub-100 MHz clock speed range. I am referring to
DriverKit, the father of IOKit.
Meanwhile, C++ is completely inappropriate for real-time operating
systems. There is a special version of C++ for embedded systems where
the overhead of C++ must be avoided.
I would like to see some modern comparisons of C++ versus ObjC, since
those 2001 WWDC notes are getting rusty. I'm talking about actual
processor cycles, not estimates based on blogs.
Brian Willoughby
Sound Consulting
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
- Follow-Ups:
- Re: c++
- From: Jens Alfke <email@hidden>
References: | |
| >c++ (From: Joel Reymont <email@hidden>) |
| >Re: c++ (From: Jens Alfke <email@hidden>) |