Counting To X
Volume Number: 15
Issue Number: 3
Column Tag: ExplainIt
Counting to X
by Dave Evans and Mark Turner
Ten Steps Toward Carbon Compatibility
Carbon is the basic element in Apple's plan to take Mac OS applications into the next
millennium. Together with Mac OS X, Carbon delivers exactly what developers have
been asking for -; an easy way of allowing Mac applications to enjoy all the advantages
of a memory protected, preemptively scheduled, multitasking operating system.
A preliminary version of the Carbon SDK has already been released to members of the
Apple Developer Program, but even if you're not a member, there's a lot you can do
now to make your transition to Mac OS X easier. And the good news is that these changes
will also provide a better experience for your customers running Mac OS 8. In this
article we'll discuss ten steps you can take to prepare for Carbon. But first, a brief
overview of Carbon and why it's important that you prepare for it now.
Carbon Defined
Carbon is a set of APIs that run on both Mac OS 8 and Mac OS X. It's a hybrid that
includes over 70 percent of the existing Mac OS APIs, covering about 95 percent of the
functions used by applications. Because it includes most of the functions you rely on
today, converting to Carbon is relatively painless. And by weeding out or modifying
certain difficult-to-support functions, Carbon provides a more streamlined and stable
base for application development.
What this means for you is that by making a small investment in Carbon, your
programs will gain these benefits when running under Mac OS X:
• Greater stability.
Preemptive multitasking and protected address spaces will help prevent other
people's bugs from crashing your application. (It goes without saying that
there are no bugs in your code!)
• Improved responsiveness.
Because all applications are guaranteed processing time through preemptive
scheduling, you don't have to worry about being locked out by another program
that's hogging the CPU. And since Mac OS X and Carbon are 100% PowerPC
native, there's no 68K emulation and no mode-switching overhead to slow
down your applications.
• Efficient use of system resources.
Your application isn't limited to a fixed heap size and can dynamically allocate
memory and other system resources based on actual needs rather than
predetermined values.
Although your current applications will continue to run unmodified in Mac OS X
through a technology code-named the Blue Box, they won't enjoy all the performance
and reliability enhancements of Mac OS X until you update them for Carbon.
That all sounds great, but the best part is that you don't have to wait for Mac OS X to
appreciate the benefits of Carbon. By cleaning up old code and adopting
Carbon-compatible APIs, your applications will run more reliably on today's Mac OS
while taking advantage of the latest Apple technologies and human interface
improvements.
Nothing's free in this world, and Carbon is no exception. It'll cost you about two weeks
work to update a typical application. But by preparing for Carbon now, your
applications will not only run better on Mac OS 8, they'll be ready to rock when Mac
OS X rolls out later this year.
Carbon Coding
Okay, time to roll up your sleeves, fire up your Mac, and give your app a tune-up.
I. Read the Carbon Paper
Before you change a single line of code, you should read Transitioning to Mac OS X: An
Overview of the Carbon Programming Interface. This white paper explains why Carbon
is so important, and defines Apple's goals for the project. It also lists the expected
level of support for all existing Mac OS APIs. You'll find the Carbon Paper, and a lot of
other helpful information, on the Carbon web site at
http://developer.apple.com/macosx/carbon/.
While you're visiting the web site, be sure to check out the official Carbon
Specification for the most up-to-date list of supported APIs. Then download the Carbon
Dater tool, because we're going to talk about it next.
II. Run Carbon Dater
If you completed Step I, you already know that Apple's Carbon Dater tool provides a
detailed report of your code's current Carbon compliance level. (If you didn't follow
Step I, shame on you! Go back and read the Carbon Paper.) Carbon Dater works by
examining PEF containers in application binaries and CFM libraries. It compares the
list of Mac OS symbols your code imports against Apple's database of Carbon-supported
functions and issues a spiffy report formatted in HTML.
In addition to analyzing your Mac OS function calls, Carbon Dater tries to identify any
attempts to read or write directly to low-memory, and it also reports if any of your
resources have the system heap bit set. Carbon applications don't have access to the
system heap in Mac OS X, so you can't load resources there.