Thursday, September 11, 2008
Carbon (API)
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.
Overview
Overview
Overview “Carbonized” application Adobe ImageReady v.7.0 running directly on Mac OS X version 10.2The 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.Some lower-level parts of Carbon, such as the File Manager, are expected to be available in 64 bit.
Overview “Carbonized” application Adobe ImageReady v.7.0 running directly on Mac OS X version 10.2The 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.Some lower-level parts of Carbon, such as the File Manager, are expected to be available in 64 bit.
Architecture
Architecture
ArchitectureCarbon 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:
File Manager — manages access to the file system, opening closing, reading and writing files. Resource Manager — manages access to resources, which are predefined chunks of data a program may require. Calls File Manager to read and write resources from disk files. Examples of resources include icons, sounds, images, templates for widgets, etc. Font Manager — manages fonts. Deprecated since Mac OS X v10.4 because it is part of QuickDraw in favor of Apple Type Services (ATS). QuickDraw — 2D graphics primitives. Deprecated since Mac OS X v10.4 in favor of Quartz 2D. Carbon Event Manager — converts user and system activity into events that code can recognise and respond to. HIObject — a completely new object-oriented API which brings to Carbon an OO model for building GUIs. This is available in Mac OS X v10.2 or later, and gives Carbon programmers some of the tools that Cocoa developers have long been familiar with. Starting with Mac OS X v10.2, HIObject is the base class for all GUI elements in Carbon. HIView is supported by Interface Builder, part of Apple's developer tools. Traditionally GUI architectures of this sort have been left to third-party application frameworks to provide. Starting with Mac OS X v10.4, HIObjects are NSObjects and inherit the ability to be serialized into data streams for transport or saving to disk. HITheme — uses QuickDraw and Quartz to render graphical user interface (GUI) elements to the screen. HITheme was introduced in Mac OS X v10.3, and Appearance Manager is a compatibility layer on top of HITheme since that version. HIView Manager — manages creation, drawing, hit-testing, and manipulation of controls. Since Mac OS X v10.2, all controls are HIViews. In Mac OS X v10.4, the Control Manager was renamed HIView Manager. Window Manager — manages creation, positioning, updating, and manipulation of windows. Since Mac OS X v10.2, windows have a root HIView. Menu Manager — manages creation, selection, and manipulation of menus. Since Mac OS X v10.2, menus are HIObjects. Since Mac OS X v10.3, menu content may be drawn using HIViews, and all standard menus use HIViews to draw.
ArchitectureCarbon 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:
File Manager — manages access to the file system, opening closing, reading and writing files. Resource Manager — manages access to resources, which are predefined chunks of data a program may require. Calls File Manager to read and write resources from disk files. Examples of resources include icons, sounds, images, templates for widgets, etc. Font Manager — manages fonts. Deprecated since Mac OS X v10.4 because it is part of QuickDraw in favor of Apple Type Services (ATS). QuickDraw — 2D graphics primitives. Deprecated since Mac OS X v10.4 in favor of Quartz 2D. Carbon Event Manager — converts user and system activity into events that code can recognise and respond to. HIObject — a completely new object-oriented API which brings to Carbon an OO model for building GUIs. This is available in Mac OS X v10.2 or later, and gives Carbon programmers some of the tools that Cocoa developers have long been familiar with. Starting with Mac OS X v10.2, HIObject is the base class for all GUI elements in Carbon. HIView is supported by Interface Builder, part of Apple's developer tools. Traditionally GUI architectures of this sort have been left to third-party application frameworks to provide. Starting with Mac OS X v10.4, HIObjects are NSObjects and inherit the ability to be serialized into data streams for transport or saving to disk. HITheme — uses QuickDraw and Quartz to render graphical user interface (GUI) elements to the screen. HITheme was introduced in Mac OS X v10.3, and Appearance Manager is a compatibility layer on top of HITheme since that version. HIView Manager — manages creation, drawing, hit-testing, and manipulation of controls. Since Mac OS X v10.2, all controls are HIViews. In Mac OS X v10.4, the Control Manager was renamed HIView Manager. Window Manager — manages creation, positioning, updating, and manipulation of windows. Since Mac OS X v10.2, windows have a root HIView. Menu Manager — manages creation, selection, and manipulation of menus. Since Mac OS X v10.2, menus are HIObjects. Since Mac OS X v10.3, menu content may be drawn using HIViews, and all standard menus use HIViews to draw.
Event handling
Event handling
Event handlingThe 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.
Event handlingThe 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.
Carbon
Carbon
Carbon is a chemical element with the symbol C and atomic number is 6. As a member of group 14 on the periodic table, it is nonmetallic and tetravalent—making four electrons available to form covalent chemical bonds. There are three naturally occurring isotopes, with 12C and 13C being stable, while 14C is radioactive, decaying with a half-life of about 5700 years.Carbon is one of the few elements known to man since antiquity. The name "carbon" comes from Latin language carbo, coal, and, in some Romance languages, the word carbon can refer both to the element and to coal.
There are several allotropes of carbon of which the best known are graphite, diamond, and amorphous carbon.The physical properties of carbon vary widely with the allotropic form. For example, diamond is highly transparent, while graphite is opaque and black. Diamond is among the hardest materials known, while graphite is soft enough to form a streak on paper. Diamond has a very low electric conductivity, while graphite is a very good conductor. Also, diamond has the highest thermal conductivity of all known materials under normal conditions. All the allotropic forms are solids under normal conditions but graphite is the most thermodynamically stable.
All forms of carbon are highly stable, requiring high temperature to react even with oxygen. The most common oxidation state of carbon in inorganic compounds is +4, while +2 is found in carbon monoxide and other transition metal carbonyl complexes. The largest sources of inorganic carbon are limestones, dolomites and carbon dioxide, but significant quantities occur in organic deposits of coal, peat, oil and methane clathrates. Carbon forms more compounds than any other element, with almost ten million pure organic compounds described to date, which in turn are a tiny fraction of such compounds that are theoretically possible under standard conditions.[11]
Carbon is the fourth most abundant element in the universe by mass after hydrogen, helium, and oxygen. It is present in all known lifeforms, and in the human body, carbon is the second most abundant element by mass (about 18.5%) after oxygen.This abundance, together with the unique diversity of organic compounds and their unusual polymer-forming ability at the temperatures commonly encountered on Earth, make this element the chemical basis of all known life.
Carbon is a chemical element with the symbol C and atomic number is 6. As a member of group 14 on the periodic table, it is nonmetallic and tetravalent—making four electrons available to form covalent chemical bonds. There are three naturally occurring isotopes, with 12C and 13C being stable, while 14C is radioactive, decaying with a half-life of about 5700 years.Carbon is one of the few elements known to man since antiquity. The name "carbon" comes from Latin language carbo, coal, and, in some Romance languages, the word carbon can refer both to the element and to coal.
There are several allotropes of carbon of which the best known are graphite, diamond, and amorphous carbon.The physical properties of carbon vary widely with the allotropic form. For example, diamond is highly transparent, while graphite is opaque and black. Diamond is among the hardest materials known, while graphite is soft enough to form a streak on paper. Diamond has a very low electric conductivity, while graphite is a very good conductor. Also, diamond has the highest thermal conductivity of all known materials under normal conditions. All the allotropic forms are solids under normal conditions but graphite is the most thermodynamically stable.
All forms of carbon are highly stable, requiring high temperature to react even with oxygen. The most common oxidation state of carbon in inorganic compounds is +4, while +2 is found in carbon monoxide and other transition metal carbonyl complexes. The largest sources of inorganic carbon are limestones, dolomites and carbon dioxide, but significant quantities occur in organic deposits of coal, peat, oil and methane clathrates. Carbon forms more compounds than any other element, with almost ten million pure organic compounds described to date, which in turn are a tiny fraction of such compounds that are theoretically possible under standard conditions.[11]
Carbon is the fourth most abundant element in the universe by mass after hydrogen, helium, and oxygen. It is present in all known lifeforms, and in the human body, carbon is the second most abundant element by mass (about 18.5%) after oxygen.This abundance, together with the unique diversity of organic compounds and their unusual polymer-forming ability at the temperatures commonly encountered on Earth, make this element the chemical basis of all known life.
Carbon cycle
Carbon cycle
Diagram of the carbon cycle. The black numbers indicate how much carbon is stored in various reservoirs, in billions of tons ("GtC" stands for gigatons of carbon; figures are circa 2004). The purple numbers indicate how much carbon moves between reservoirs each year. The sediments, as defined in this diagram, do not include the ~70 million GtC of carbonate rock and kerogen.Under terrestrial conditions, conversion of one element to another is very rare. Therefore, the amount of carbon on Earth is effectively constant. Thus, processes that use carbon must obtain it somewhere and dispose of it somewhere else. The paths that carbon follows in the environment make up the carbon cycle. For example, plants draw carbon dioxide out of their environment and use it to build biomass, as in carbon respiration or the Calvin cycle, a process of carbon fixation. Some of this biomass is eaten by animals, whereas some carbon is exhaled by animals as carbon dioxide. The carbon cycle is considerably more complicated than this short loop; for example, some carbon dioxide is dissolved in the oceans; dead plant or animal matter may become petroleum or coal, which can burn with the release of carbon, should bacteria not consume it.
Diagram of the carbon cycle. The black numbers indicate how much carbon is stored in various reservoirs, in billions of tons ("GtC" stands for gigatons of carbon; figures are circa 2004). The purple numbers indicate how much carbon moves between reservoirs each year. The sediments, as defined in this diagram, do not include the ~70 million GtC of carbonate rock and kerogen.Under terrestrial conditions, conversion of one element to another is very rare. Therefore, the amount of carbon on Earth is effectively constant. Thus, processes that use carbon must obtain it somewhere and dispose of it somewhere else. The paths that carbon follows in the environment make up the carbon cycle. For example, plants draw carbon dioxide out of their environment and use it to build biomass, as in carbon respiration or the Calvin cycle, a process of carbon fixation. Some of this biomass is eaten by animals, whereas some carbon is exhaled by animals as carbon dioxide. The carbon cycle is considerably more complicated than this short loop; for example, some carbon dioxide is dissolved in the oceans; dead plant or animal matter may become petroleum or coal, which can burn with the release of carbon, should bacteria not consume it.
Organic compounds
Organic compounds
Structural formula of methane, the simplest possible organic compoundCarbon has the ability to form very long chains interconnecting C-C bonds. This property is called catenation. Carbon-carbon bonds are strong, and stable.[citation needed] This property allows carbon to form an almost infinite number of compounds; in fact, there are more known carbon-containing compounds than all the compounds of the other chemical elements combined except those of hydrogen (because almost all organic compounds contain hydrogen too).
The simplest form of an organic molecule is the hydrocarbon—a large family of organic molecules that are composed of hydrogen atoms bonded to a chain of carbon atoms. Chain length, side chains and functional groups all affect the properties of organic molecules. By IUPAC's definition, all the other organic compounds are functionalized compounds of hydrocarbons.[citation needed]
Structural formula of methane, the simplest possible organic compoundCarbon has the ability to form very long chains interconnecting C-C bonds. This property is called catenation. Carbon-carbon bonds are strong, and stable.[citation needed] This property allows carbon to form an almost infinite number of compounds; in fact, there are more known carbon-containing compounds than all the compounds of the other chemical elements combined except those of hydrogen (because almost all organic compounds contain hydrogen too).
The simplest form of an organic molecule is the hydrocarbon—a large family of organic molecules that are composed of hydrogen atoms bonded to a chain of carbon atoms. Chain length, side chains and functional groups all affect the properties of organic molecules. By IUPAC's definition, all the other organic compounds are functionalized compounds of hydrocarbons.[citation needed]
Subscribe to:
Posts (Atom)
