Netencyclo, The wikipedia mirror - The biggest multilingual encyclopedia : Carbon (computing)

- Carbon (computing) -

Carbon (computing) :

Carbon (API)

From Wikipedia, the free encyclopedia

  (Redirected from Carbon (computing))
Jump to: navigation, search
Carbon
Developed by Apple Inc.
OS Mac OS X
Type Widget toolkit
License Proprietary
Website developer.apple.com/carbon/

Carbon is Apple Inc.'s procedural API for the Macintosh operating system, which permits a good degree of forward and backward compatibility between source code written to run on the older and now dated Classic Mac OS (Version 8.1 and later), and the newer Mac OS X. It is one of five APIs natively available for Mac OS X; the others are Cocoa, POSIX, Toolbox (for the obsolete Classic environment), and Java. Carbon is not fully compatible with 64-bit programs under Mac OS 10.5.

Contents

[edit] Overview

“Carbonized” application Adobe ImageReady v.7.0 running directly on Mac OS X version 10.2

The Carbon APIs are published and accessed in the form of C header files and dynamically linkable libraries. In Mac OS X, much functionality is contained in ApplicationServices.framework. In Classic Mac OS, most functions are in a single library called CarbonLib. These different implementations of the APIs are interchangeable from the perspective of the executable. This permits a program that conforms to the Carbon specification to run natively on both operating systems. However, if an application uses a single function not in Carbon, compatibility with Mac OS X requires the Classic environment.

The Carbon APIs were designed to include as many of the older Toolbox APIs as possible, to permit easy porting of most legacy code to Mac OS X. Such porting was known as Carbonization. Carbon also added new functionality and new abstractions. Previously, many data structures of the OS were exposed and manipulated directly by the program. In Carbon, most such structures became fully opaque, and many new APIs were added to access them. This encouraged cleaner and less error-prone code, and made it easier for Apple to modify the operating system. Carbon removed some functions that were specifically attached to the older Mac OS, and removed some obsolete technologies altogether. Backward compatibility remained a focus as long as Mac OS 9 was developed, as later updates such as 9.2.2 were largely to improve support for newer software. However, little Carbon software today remains compatible with Mac OS 9, as the interface has continued to evolve. Carbon was not intended to guarantee backward compatibility. If a programmer desires compatibility with Mac OS 9.1, they must test and debug it with Mac OS 9.1 specifically. Between Mac OS 8.6 and Mac OS 9.2.2, CarbonLib gradually evolved from an adaptation of the QuickTime for Windows user interface API into the basis for much of the later Classic Mac OS development.

Carbon is sometimes seen as a transitional or legacy technology. This is incorrect, and it is misleading to describe it as a technology per se. Carbon is a set of application-level Mac OS X APIs for the C programming language. They are the most efficient alternative when the underlying operating system functionality is also implemented in C. They are also the most versatile, accessible from C, C++, Pascal, Ada, or any other language with suitable interface headers. A higher level approach may be taken with Carbon by using an application framework built on it, for example MacApp, Metrowerks PowerPlant or MacZoop. Many parts of the Cocoa API likewise implement Carbon for Objective-C. Also, many Carbon APIs provide C language access to functionality implemented in Objective-C. In general, it is inefficient for a programmer to be overly concerned with the underlying operating system implementation.

At WWDC 2007, Apple revealed that it will not be possible to compile Carbon apps as 64-bit code for Leopard, contrary to previous statements.[1] Some lower-level parts of Carbon, such as the File Manager, are expected to be available in 64 bit.

[edit] Architecture

Carbon descends from the Toolbox, and as such, is composed of "Managers". Each Manager is a functionally-related API, defining sets of data structures and functions to manipulate them. Managers are often interdependent or layered.

Newer parts of Carbon tend to be much more object-oriented in their conception, most of them based on Core Foundation. Some Managers, such as the HIView Manager (a superset of the Control Manager), are implemented in C++, but Carbon remains a C API.

Some examples of Carbon Managers:

[edit] Event handling

The Mac Toolbox's Event Manager originally used a polling model for application design. The application's main event loop asks the Event Manager for an event using GetNextEvent. If there is an event in the queue, the Event Manager passes it back to the application, where it is handled, otherwise it returns immediately. This behavior is called "busy-waiting", running the event loop unnecessarily. Busy-waiting reduces the amount of CPU time available for other applications and decreases battery power on laptops. The classic Event Manager dates from the original Mac OS in 1984, when whatever application was running was guaranteed to be the only application running, and where power management was not a concern.

With the advent of System 7.0 and the ability to run more than one application simultaneously came a new Event Manager call, WaitNextEvent, which allows an application to specify a sleep interval. One easy trick for legacy code to adopt a more efficient model without major changes to its source code is simply to set the sleep parameter passed to WaitNextEvent to a very large value—on OS X, this puts the thread to sleep whenever there is nothing to do, and only returns an event when there is one to process. In this way, the polling model is quickly inverted to become equivalent to the callback model, with the application performing its own event dispatching in the original manner. There are loopholes, though. For one, the legacy toolbox call ModalDialog, for example, calls the older GetNextEvent function internally, resulting in polling in a tight loop without blocking.

Carbon introduces a replacement system, called the Carbon Event Manager. (The original Event Manager still exists for compatibility with legacy applications). Carbon Event Manager provides the event loop for the developer (based on Core Foundation's CFRunLoop in the current implementation); the developer sets up event handlers and enters the event loop in the main function, and waits for Carbon Event Manager to dispatch events to the application.

[edit] Timers

In the classic Mac OS, there was no operating system support for application level timers (the lower level Time Manager was available, but executed timer callbacks at interrupt time, during which you could not safely make calls to most Toolbox routines). Timers were usually left to application developers to implement, and this was usually done by counting elapsed time during the idle event - that is, an event that was returned by WaitNextEvent when any other event wasn't available. In order for such timers to have reasonable resolution, developers could not afford WNE to delay too long, and so low "sleep" parameters were usually set. This results in highly inefficient scheduling behaviour, since the thread will not sleep for very long, instead repeatedly waking to return these idle events. Apple added timer support to Carbon to address this problem -- the system can schedule timers with great efficiency.

[edit] Notes

[edit] External links

Carbon (computing) - Related Items

Carbon (computing) - In the news

© 2008 Netencyclo - Netencyclo Home - Terms of Service - Privacy Policy - Program Policies
Netencyclo, the Wikipedia mirror : the biggest multilingual free-content encyclopedia on the Internet. It uses material from the Wikipedia article Carbon (computing). All Wikipedia content is licensed under the GNU Free Documentation License (see details). Content on this web site is provided for informational purposes only. We accept no responsibility for any loss, injury or inconvenience sustained by any person resulting from information published on this site. We encourage you to verify any critical information with the relevant authorities.