Jan 99 Getting Started
Volume Number: 15
Issue Number: 1
Column Tag: Getting Started
Carbon: Getting Ready for Mac OS X
by Dan Parks Sydow
Becoming familiar with the Carbon API to ready your
code for Mac OS X
In the previous few months we've covered a variety of graphics-related programming
topics, including bringing color and animation to your Mac programs. In future
articles we'll discuss other multimedia enhancements (such as sound-playing) that
you can incorporate into your own code. This month, however, we'll take a pause in the
multimedia action to look at what is becoming a very important topic to all Mac
programmers: Mac OS X and the Carbon application programming interface.
Apple will seed the beta version of Mac OS X to select developers next month. Some of
you readers may be in the group lucky enough to be getting your hands on a copy of the
new, modern operating system. But even if you won't be getting a sneak-peek at Mac OS
X, there are still plenty of things you can do to ensure that your own program -
whether trivial or all-powerful - is ready for the prime-time release of Mac OS X
later this year.
About Mac OS X
By now you've certainly read numerous magazine columns, online reports, and even
newspaper articles, devoted to Mac OS X. So we can be succinct here in our definition of
just what Mac OS X is. Mac OS X is the version of the Macintosh operating system that's
to bring about the important new features and enhancements that all developers and
many users have clamored for. Applications running in Mac OS X will have a number of
advantages over applications running in previous versions of the Mac OS X. In short,
these advantages are:
Increased stability A protected address space means memory protection. When a
program "goes bad" it may crash, but it won't take down other applications or crash
the system.
Increased responsiveness Preemptive multitasking means that the processor is better
able to service all running applications, resulting in each application being more
responsive.
Dynamic resource allocation Applications use system resources (such as memory) as
needed - they don't need to specify and adhere to predetermined values.
Okay, Mac OS X sounds pretty cool - users will really experience faster applications
and fewer crashes. But what do these enhancements mean for us programmers? The
answer to that question is the basis of this article, so read on!
About Carbon
API stands for application programming interface, and it's the means of helping
programmers develop applications that make use of, or interface with, the code that
comprises the operating system. Each operating system has its own API, so to make it
quickly evident which API a programmer is referring to, each API has a name. As you
know from reading Getting Started, the API Macintosh programmers use is referred to
as the Macintosh Toolbox (or the Mac Toolbox, or simply the Toolbox). The Macintosh
Toolbox, like any API, is nothing more than a set (albeit a very large set) of routines.
When you learn how to make use of these routines, you know how to write programs.
Mac OS X will introduce a host of changes to the Macintosh operating system, so a new
means of allowing programmers to interface with the OS is needed. Carbon is that
means. Carbon, like the Toolbox, is the set of programming interfaces a programmer
uses to develop Macintosh applications. Specifically, Carbon is the set of routines
programmers use to develop Mac OS X applications that can also run on Mac OS 8.
When a programmer writes a program using Carbon, that program takes advantage of
the features new to Mac OS X, such as preemptive multitasking, memory protection,
and dynamic resource allocation.
What happens when you run a "carbonized" application on a Mac hosting Mac OS 8
rather than on a Mac hosting Mac OS X? It will run just fine. It won't, however, be
more responsive or more stable than any other Mac OS 8 application. Mac OS 8 will
simply consider it another Mac OS 8 application. Copy that same application to a Mac
hosting Mac OS X, though, and the carbonized program will exhibit the traits expected
of a Mac OS X application. To summarize:
Macintosh Toolbox The API for developing applications that run on a Macintosh
computer hosting any version of the Mac OS prior to Mac OS X (such as Mac OS 8.5,
Mac OS 7.6, and so forth).
Carbon The API for developing applications that can run on a Macintosh computer
hosting Mac OS X or any version of Mac OS 8.
Learning a new API can be a daunting task. If you're a regular reader of Getting
Started, you are probably just beginning to feel comfortable with using the Macintosh
Toolbox API. If tomorrow you were asked to develop a program that would run on a PC
hosting Windows 95 or Windows 98, you'd have your work cut out for you. While some
general programming principles would translate from one operating system to the
other, your API knowledge would be all but useless - Windows has its own huge set of
API routines that a programmer uses to develop a Windows application. This all sounds
pretty ominous, but it isn't. It's just a setup to let you know how easy you, the Mac
programmer, has it. Why? Because the transition from the Macintosh Toolbox API to