Thursday, March 26, 2009

Upgrade existing Eclipse to 3.4.2

Download the latest version 3.4.2 from eclipse site
http://www.eclipse.org/downloads/
http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/ganymede/SR2/eclipse-jee-ganymede-SR2-win32.zip

Download Jboss or other plug-ins you want to install

Extract new Eclipse version to the old eclipse folder
Overwrite everything in the old folder

Run eclipse
first time should have error, no matter, just close the environment and run it again. Then should success.

How to - Leverage pattern matching in BlackBerry smartphone applications to provide an integrated user experience

Please take a look of httpfilterdemo from the blackberry samples in SDK, if it fits your requirement, do not read this doc.

Summary

This article applies to the following:

* BlackBerry® Device Software 4.0 and later
* BlackBerry smartphones

Description
Background

You may have noticed how certain strings are underlined in native BlackBerry smartphone applications. For example, phone numbers are underlined or highlighted when composing or reading messages. Once selected, these special strings are assigned a context-sensitive menu item, for example call a phone number. Third-party applications can take advantage of this functionality to add custom context-sensitive menu items to standard BlackBerry smartphone applications. These menu items can be used to launch a custom application, open the BlackBerry® Browser to a specific URL, send a message, or do any number of other things.

This functionality can be achieved by using one of two application programming interfaces (APIs):

1. net.rim.device.api.util.StringPattern - This API was introduced in BlackBerry Device Software 4.0 and requires you to implement your own string matching algorithm.
2. net.rim.blackberry.api.stringpattern.PatternRepository - This API was introduced in BlackBerry Device Software 4.3.0, and allows the use of Perl style regular expressions.

The samples provided in this article match a United States zip code and allow the BlackBerry smartphone user to lookup more information on the zip code.
Procedure
net.rim.device.api.util.StringPattern

The StringPattern source code example uses the string pattern matching that was introduced in BlackBerry Device Software 4.0. It requires implementing another string matching algorithm.

There are four major components required for this implementation

net.rim.device.api.util.StringPattern - This class represents the pattern that you want to recognize. It can be as simple as a zip code, or as complex as an address in its various forms. To write an effective StringPattern, remember that each character typed into the applicable field will be parsed by your implementation. As such, efficiency is important in this class.

net.rim.device.api.ui.component.MenuItem - The MenuItem includes the majority of the implementation for this capability. The MenuItem typically includes or references the action that will occur once a match is found and invoked by the BlackBerry smartphone user. For example, the run method for the MenuItem is invoked when a zip code has been recognized and the BlackBerry smartphone user selects the Lookup Zipcode menu item.

net.rim.device.api.ui.component.ActiveFieldCookie - The ActiveFieldCookie is a container object that allows the StringPattern class to transfer the context-sensitive information to the MenuItem. It also allows the implementation to add the appropriate menu item, or multiple menu items, when a string pattern match is found.

net.rim.device.api.util.Factory - The implementation of the Factory class links the StringPattern to the ActiveFieldCookie when a match is recorded in the StringPattern implementation. Typically, the Factory implementation is quite compact but a necessary requirement for the system.

The ZipCodeLookupSample class provides the starting point for the application. The application is configured as an auto-start system module so that all of the components can be registered upon start up. It is important to note that the main class initializes all of the required components described above, and has been implemented carefully to only initialize these components once.
net.rim.blackberry.api.stringpattern.PatternRepository

The PatternRepository source code sample uses the API that was introduced in BlackBerry Device Software 4.3.0 and allows the use of regular expressions for string matching, which makes the sample much simpler than the prior sample.

There are two major components required for this implementation

net.rim.blackberry.api.stringpattern.PatternRepository - This class will register a Perl-style regular expression or a specific string with the systems pattern repository. When a match is found the ApplicationMenuItem(s) associated with the pattern will appear in the current application's menu.

net.rim.blackberry.api.menuitem.ApplicationMenuItem- The ApplicationMenuItem includes the action that will occur once a match is found and is invoked by the BlackBerry smartphone user.

The application is once again configured as an auto-start system module. This is done to register the regular expression and menu item with the systems pattern repository upon system start up.

To access the sample code, download the attached ZipCodeLookupSamples.zip file.

Tuesday, March 24, 2009

Integer (computer science)

Integer (computer science)

From Wikipedia, the free encyclopedia

Jump to: navigation, search

In computer science, the term integer is used to refer to a data type which represents some finite subset of the mathematical integers. These are also known as integral data types.

Contents

[hide]

[edit] Value and representation

The value of a datum with an integral type is the mathematical integer that it corresponds to. The representation of this datum is the way the value is stored in the computer’s memory. Integral types may be unsigned (capable of representing only non-negative integers) or signed (capable of representing negative integers as well).

The most common representation of a positive integer is a string of bits, using the binary numeral system. The order of the bits varies; see endianness. The width or precision of an integral type is the number of bits in its representation. An integral type with n bits can encode 2n numbers; for example an unsigned type typically represents the non-negative values 0 through 2n−1.

There are three different ways to represent negative numbers in a binary numeral system. The most common is two’s complement, which allows a signed integral type with n bits to represent numbers from −2(n−1) through 2(n−1)−1. Two’s complement arithmetic is convenient because there is a perfect one-to-one correspondence between representations and values, and because addition, subtraction and multiplication do not need to distinguish between signed and unsigned types. The other possibilities are sign-magnitude and ones' complement. See Signed number representations for details.

Another, rather different, representation for integers is binary-coded decimal, which is still commonly used in mainframe financial applications and in databases.

[edit] Common integral data types

Bits Name Range Decimal digits Uses
8 byte, octet Signed: −128 to +127 3 ASCII characters, C/C++ char, C/C++ int8_t, Java byte, C# byte
Unsigned: 0 to +255 3
16 halfword, word Signed: −32,768 to +32,767 5 UCS-2 characters, C/C++ short, C/C++ int16_t, Java short, C# short, Java char
Unsigned: 0 to +65,535 5
32 word, long, doubleword, longword Signed: −2,147,483,648 to +2,147,483,647 10 UCS-4 characters, Truecolor with alpha, C/C++ long (on Windows and 32-bit Unix), C/C++ int32_t, Java int, C# int, FourCC
Unsigned: 0 to +4,294,967,295 10
64 doubleword, longword, long long, quad, quadword Signed: −9,223,372,036,854,775,808 to +9,223,372,036,854,775,807 19 C/C++ long (on 64-bit Unix), C/C++ long long, C/C++ int64_t, Java long, C# long
Unsigned: 0 to +18,446,744,073,709,551,615 20
128 octaword Signed: −170,141,183,460,469,231,731,687,303,715,884,105,728 to +170,141,183,460,469,231,731,687,303,715,884,105,727 39 C only available as non-standard compiler-specific extension
Unsigned: 0 to +340,282,366,920,938,463,463,374,607,431,768,211,455 39
n n-bit integer
(general case)
Signed: ( − 2n − 1) to (2n − 1 − 1) \lceil (n-1) \log_{10}{2} \rceil Ada range 2**(n-1) .. 2**n;
Unsigned: 0 to (2n − 1) \lceil n \log_{10}{2} \rceil Ada mod 2**n;

Different CPUs support different integral data types. Typically, hardware will support both signed and unsigned types but only a small, fixed set of widths.

The table above lists integral type widths that are supported in hardware by common processors. High level programming languages provide more possibilities. It is common to have a ‘double width’ integral type that has twice as many bits as the biggest hardware-supported type. Many languages also have bit-field types (a specified number of bits, usually constrained to be less than the maximum hardware-supported width) and range types (which can represent only the integers in a specified range).

Some languages, such as Lisp, REXX and Haskell, support arbitrary precision integers (also known as infinite precision integers or bignums). Other languages which do not support this concept as a top-level construct may have libraries available to represent very large numbers using arrays of smaller variables, such as Java's BigInteger class or Perl's "bigint" package. These use as much of the computer’s memory as is necessary to store the numbers; however, a computer has only a finite amount of storage, so they too can only represent a finite subset of the mathematical integers. These schemes support very large numbers, for example one kilobyte of memory could be used to store numbers up to 2466 digits long.

A Boolean or Flag type is a type which can represent only two values: 0 and 1, usually identified with false and true respectively. This type can be stored in memory using a single bit, but is often given a full byte for convenience of addressing and speed of access.

A four-bit quantity is known as a nibble (when eating, being smaller than a bite) or nybble (being a pun on the form of the word byte). One nibble corresponds to one digit in hexadecimal and holds one digit or a sign code in binary-coded decimal.

[edit] Bytes and octets

The term byte initially meant ‘the smallest addressable unit of memory’. In the past, 5-, 6-, 7-, 8-, and 9-bit bytes have all been used. There have also been computers that could address individual bits (‘bit-addressed machine’), or that could only address 16- or 32-bit quantities (‘word-addressed machine’). The term byte was usually not used at all in connection with bit- and word-addressed machines.

The term octet always refers to an 8-bit quantity. It is mostly used in the field of computer networking, where computers with different byte widths might have to communicate.

In modern usage byte almost invariably means eight bits, since all other sizes have fallen into disuse; thus byte has come to be synonymous with octet.

[edit] Words

The term word is used for a small group of bits which are handled simultaneously by processors of a particular architecture. The size of a word is thus CPU-specific. Many different word sizes have been used, including 6-, 8-, 12-, 16-, 18-, 24-, 32-, 36-, 39-, 48-, 60-, and 64-bit. Since it is architectural, the size of a word is usually set by the first CPU in a family, rather than the characteristics of a later compatible CPU. The meanings of terms derived from word, such as longword, doubleword, quadword, and halfword, also vary with the CPU and OS.

As of 2008 practically all new desktop processors are of the x86-64 family and capable of using 64-bit words, they are however often used in 32-bit mode. Embedded processors with 8- and 16-bit word size are still common. The 36-bit word length was common in the early days of computers.

One important cause of non-portability of software is the incorrect assumption that all computers have the same word size as the computer used by the programmer. For example, if a programmer using the C language incorrectly declares as int a variable that will be used to store values greater than 216 − 1, the program will fail on computers with 16-bit integers. That variable should have been declared as long, which has at least 32 bits on any computer. Programmers may also incorrectly assume that a pointer can be converted to an integer without loss of information, which may work on (some) 32-bit computers, but fail on 64-bit computers with 64-bit pointers and 32-bit integers.

[edit] See also

[edit] Notes

Wednesday, March 18, 2009

Media types supported on the BlackBerry smartphone

Media types supported on the BlackBerry smartphone


Doc ID : KB05482
Last Modified : 01-20-2009
Document Type : Support



Environment

  • BlackBerry® smartphones



Overview

In the Media application on the BlackBerry smartphone, you can open media files such as videos, ring tones, pictures, and songs that are stored in the BlackBerry smartphone memory or on a media card.

Note: For instructions on how to transcode audio and video files for the Media application, see KB05419.


The following tables list what codecs are recommended and supported for each specific file format for video and audio on the different BlackBerry smartphones, as well as whether Real Time Streaming Protocol (RTSP) streaming is supported using that file format.

BlackBerry® Storm™ 9500 smartphone and BlackBerry® Storm™ 9530 smartphone

Supported formats

File Format / Extension Component Codec Notes RTSP Streaming

MP4

M4A

3GP

3GP2

Video H.264 Baseline Profile, 480x360 pixels, up to 2 Mbps, 30 frames per second Supported
MPEG4 Simple Profile Level 3, 480x360 pixels, up to 2 Mbps, 30 frames per second Supported
H.263 Profile 0 and 3, Level 30 Supported
Audio AAC-LC, AAC+, eAAC+
Supported
AMR-NB
Supported
QCELP EVRC

AVI Video MPEG4 Simple Profile Level 3, 480x360 pixels, up to 2 Mbps, 30 frames per second Supported
Audio MP3

ASF

WMV

WMA

Video Windows® Media Video 9 WMV3, Simple Profile, 480x360 pixels, 30 frames per second
Audio Windows Media Audio 9
Supported
Windows Media 10 Standard/Professional
Supported
MP3 Audio MP3



Recommended video format for local playback

File Format / Extension Component Codec Notes
MP4 Video H.264 Baseline Profile, 480x360 pixels, up to 2 Mbps, 30 frames per second
Audio AAC-LC



BlackBerry® Curve™ 8900 smartphone

Supported formats

File Format / Extension Component Codec Notes RTSP Streaming
MP4

M4A

MOV

3GP
Video H.264 Baseline Profile, 480x360 pixels, up to 1500 kbps, 24 frames per second Supported
MPEG4 Simple and Advance Simple Profile, 480x360 pixels, up to 1500 kbps, 24 frames per second Supported
H.263 Profile 0 and 3, Level 45 Supported
Audio AAC-LC, AAC+, eAAC+
Supported
AMR-NB
Supported
AVI Video MPEG4 Simple and Advance Simple Profile, 480x360 pixels, up to 1500 kbps, 24 frames per second Supported
Audio MP3

ASF

WMV

WMA
Video Windows Media Video 9 WMV3, Simple and Main Profile, 480x360 pixels, 24 frames per second
Audio Windows Media Audio 9 Standard/Professional

Windows Media 10 Standard/Professional

MP3 Audio MP3



Recommended video format for local playback

File Format / Extension Component Codec Notes
MP4 Video MPEG4 Advance Simple Profile, 480x360 pixels, up to 1500 kbps, 24 frames per second
Audio AAC-LC



BlackBerry® Bold™ 9000 smartphone

Supported formats

File Format / Extension Component Codec Notes RTSP Streaming
MP4

M4A

MOV

3GP
Video H.264 Baseline Profile, 480x320 pixels, up to 1500 kbps, 24 frames per second Supported
MPEG4 Simple and Advance Simple Profile, 480x320 pixels, up to 1500 kbps, 24 frames per second Supported
H.263 Profile 0 and 3, Level 45 Supported
Audio AAC-LC, AAC+, eAAC+
Supported
AMR-NB
Supported
AVI Video MPEG4 Simple and Advance Simple Profile, 480x320 pixels, up to 1500 kbps, 24 frames per second Supported
Audio MP3

ASF

WMV

WMA
Video Windows Media Video 9 WMV3, Simple and Main Profile, 480x320 pixels, 24 frames per second
Audio Windows Media Audio 9 Standard/Professional

Windows Media 10 Standard/Professional

MP3 Audio MP3



Recommended video format for local playback

File Format / Extension Component Codec Notes
MP4 Video MPEG4 Advance Simple Profile, 480x320 pixels, up to 1500 kbps, 24 frames per second
Audio AAC-LC



BlackBerry® Pearl™ 8100, BlackBerry® Pearl™ 8110, BlackBerry® Pearl™ 8120, and BlackBerry® Pearl™ 8220 smartphones (Global System for Mobile communications (GSM®), General Packet Radio Service (GPRS), and Enhanced Data Rates for Global Evolution (EDGE) networks)

Supported formats

File Format / Extension Component Codec Notes RTSP Streaming
MP4

M4A

MOV

3GP
Video MPEG4 Simple Profile, 240x320 pixels, up to 768 kbps, 24 frames per second Supported
H.263 Profile 0 and 3, Level 45 Supported
Audio AAC-LC, AAC+, eAAC+
Supported
AMR-NB
Supported
AVI Video MPEG4 Simple and Advance Simple Profile, 240x320 pixels, up to 768 kbps, 24 frames per second Supported
Audio MP3

ASF

WMV

WMA
Video Windows Media Video 9 WMV3, Simple Profile, 240x320 pixels, 24 frames per second
Audio Windows Media Audio 9 Standard/Professional

Windows Media 10 Standard/Professional

MP3 Audio MP3



Recommended video format for local playback (BlackBerry® Device Software 4.5)

File Format / Extension Component Codec Notes
MP4 Video MPEG4 Simple Profile, 240x320 pixels, up to 768 kbps, 24 frames per second
Audio AAC-LC


Recommended video format for local playback (BlackBerry Device Software 4.2 and 4.3)

File Format / Extension Component Codec Notes
AVI Video MPEG4 Simple Profile, 240x320 pixels, up to 768 kbps, 24 frames per second
Audio MP3



BlackBerry® Curve™ 8300, BlackBerry® Curve™ 8310, BlackBerry® Curve™ 8320, and BlackBerry® Curve™ 8350i smartphones, and BlackBerry® 8800 and BlackBerry® 8820 smartphones (GSM/GPRS/EDGE networks)

Supported formats

File Format / Extension Component Codec Notes RTSP Streaming

MP4

M4A

MOV

3GP

Video MPEG4 Simple Profile, 320x240 pixels, up to 768 kbps, 24 frames per second Supported
H.263 Profile 0 and 3, Level 45 Supported
Audio AAC-LC, AAC+, eAAC+
Supported
AMR-NB
Supported

AVI

Video MPEG4 Simple and Advance Simple Profile, 320x240 pixels, up to 768 kbps, 24 frames per second Supported
Audio MP3

ASF

WMV

WMA

Video Windows Media Video 9 WMV3, Simple Profile, 320x240 pixels, 24 frames per second
Audio Windows Media Audio 9 Standard/Professional

Windows Media 10 Standard/Professional

MP3

Audio MP3



Recommended video format for local playback (BlackBerry Device Software 4.5)

File Format / Extension Component Codec Notes

MP4

Video MPEG4 Simple Profile, 320x240 pixels, up to 768 kbps, 24 frames per second
Audio AAC-LC


Recommended video format for local playback (BlackBerry Device Software 4.2 and 4.3)

File Format / Extension Component Codec Notes
AVI Video MPEG4 Simple Profile, 320x240 pixels, up to 768 kbps, 24 frames per second
Audio MP3



BlackBerry® Pearl™ 8130 smartphone (Code Division Multiple Access (CDMA) network)

Supported formats

File Format / Extension Component Codec Notes RTSP Streaming

MP4

3GP

Video MPEG4 Simple Profile, 240x320 pixels, up to 768 kbps, 24 frames per second Supported
H.263 Profile 0 and 3, Level 45 Supported
Audio AAC-LC, AAC+, eAAC+
Supported
AMR-NB
Supported

ASF

WMV

WMA

Video Windows Media Video 9 WMV3, Simple Profile, 240x320 pixels, 24 frames per second
Audio Windows Media Audio 9 Standard/Professional

Windows Media 10 Standard/Professional

MP3

Audio MP3



Recommended video format for local playback

File Format / Extension Component Codec Notes

MP4

Video MPEG4 Simple Profile, 240x320 pixels, up to 384 kbps, 24 frames per second
Audio AAC-LC



BlackBerry® Curve™ 8330 smartphone and BlackBerry™ 8830 smartphone (CDMA network)

Supported formats

File Format / Extension Component Codec Notes RTSP Streaming
MP4

3GP
Video MPEG4 Simple Profile, 320x240 pixels, up to 768 kbps, 24 frames per second Supported
H.263 Profile 0 and 3, Level 45 Supported
Audio AAC-LC, AAC+, eAAC+
Supported
AMR-NB
Supported
ASF

WMV

WMA
Video Windows Media Video 9 WMV3, Simple Profile, 320x240 pixels, 24 frames per second
Audio Windows Media Audio 9 Standard/Professional

Windows Media 10 Standard/Professional

MP3 Audio MP3



Recommended video format for local playback

File Format / Extension Component Codec Notes
MP4 Video MPEG4 Simple Profile, 320x240 pixels, up to 768 kbps, 24 frames per second
Audio AAC-LC





Additional Information

Note: Streaming requires BlackBerry Device Software 4.3 or later.

Monday, March 16, 2009

Mobile Media API Overview

Mobile Media API Overview




The Mobile Media API (MMAPI) provides a powerful, flexible, and simple interface to multimedia capabilities. It exposes a clean interface for playing and recording audio and video data. This article provides an overview of the concepts of the MMAPI and a quick tour of its classes and interfaces.

Mobile Media API Architecture

The Mobile Media API is based on four fundamental concepts:

  1. A player knows how to interpret media data. One type of player, for example, might know how to produce sound based on MP3 audio data. Another type of player might be capable of showing a QuickTime movie. Players are represented by implementations of the javax.microedition.media.Player interface.
  2. You can use one or more controls to modify the behavior of a player. You can get the controls from a Player instance and use them while the player is rendering data from media. For example, you can use a VolumeControl to modify the volume of a sampled audio Player. Controls are represented by implementations of the javax.microedition.media.Control interface; specific control subinterfaces are in the javax.microedition.media.control package.
  3. A data source knows how to get media data from its original location to a player. Media data can be stored in a variety of locations, from remote servers to resource files or RMS databases. Media data may be transported from its original location to the player using HTTP, a streaming protocol like RTP, or some other mechanism. javax.microedition.media.protocol.DataSource is the abstract parent class for all data sources in the Mobile Media API.
  4. Finally, a manager ties everything together and serves as the entry point to the API. The javax.microedition.media.Manager class contains static methods for obtaining Players or DataSources.

Using the Mobile Media API

The simplest thing you can do with Manager is play tones using the following method:

public static void playTone(int note,
int duration, int volume) throws MediaException

The duration is specified in milliseconds and the volume ranges from 0 (silent) to 100 (loud). The note is specified as a number, as in MIDI, where 60 is middle C and 69 is a 440 Hz A. The note can range from 0 to 127. The playTone() method is appropriate for playing a single tone or a very short sequence. For longer monotonic sequences, you'll use the default tone player, which is capable of playing an entire sequence of tones.

The real magic of the Mobile Media API is exposed through Manager's createPlayer() method. There are three different versions of this method as follows:

public static Player createPlayer(String locator)
throws IOException, MediaException
public static Player createPlayer(DataSource source)
throws IOException, MediaException
public static Player createPlayer(InputStream stream, String type)
throws IOException, MediaException

The simplest way to obtain a Player is to use the first version of createPlayer() and just pass in a string that represents media data. For instance, you might specify an audio file on a web server:

Player p = Manager.createPlayer("http://webserver/music.mp3");

The other createPlayer() methods allow you to create a Player from a DataSource or an InputStream, whatever you happen to have available. If you think about it, these three methods are really just three different ways of getting at the media data, the actual bits. An InputStream is the simplest object, just a byte stream. The DataSource is the next level up, an object that speaks a protocol to get access to media data. And passing a locator string is the ultimate shortcut: the MMAPI figures out which protocol to use and gets the media data to the Player.

Using a Player

Once you've successfully created a Player, what do you do next? The simplest action is to begin playback with the start() method. For anything beyond the rudiments, however, it helps to understand the life cycle of a Player. This consists of four states.

When a Player is first created, it is in the UNREALIZED state. After a Player has located its data, it is in the REALIZED state. If a Player is rendering an audio file from an HTTP connection to a server, for example, the Player reaches REALIZED after the HTTP request is sent to the server, the HTTP response is received, and the DataSource is ready to begin retrieving audio data. The next state is PREFETCHED, and is achieved when the Player has read enough data to begin rendering. Finally, when the data is being rendered, the Player's state is STARTED.

The Player interface provides methods for state transitions, both forwards and backwards through the cycle described above. The reason is to provide the application with control over operations that might take a long time. You might, for example, want to push a Player through the REALIZED and PREFETCHED states so that a sound can be played immediately in response to a user action.

The Mobile Media API in the Java Platform

Where exactly does the MMAPI fit in the Java 2 platform? The answer is just about anywhere. Although the MMAPI was designed with the contraints of the CLDC in mind, it will work just fine alongside either CLDC or CDC software stacks. As a matter of fact, the MMAPI can be implemented with J2SE as a lightweight alternative to the Java Media Framework.

What Media Types are Supported?

If you get a device that supports the Mobile Media API, what kinds of data can it play? What data transfer protocols are supported? The Mobile Media API doesn't require any specific content types or protocols, but you can find out at runtime what is supported by calling Manager's getSupportedContentTypes() and getSupportedProtocols() methods.

What's the worst that can happen? If you ask Manager to give you a Player for a content type or protocol that is not supported, it will throw an exception. Your application should attempt to recover gracefully from such an exception, perhaps by using a different content type or displaying a polite message to the user.

Media in MIDP 2.0

The MIDP 2.0 specification includes a subset of the Mobile Media API. It is upwardly compatible with the full API. The MIDP 2.0 subset has the following characteristics:

  • Only audio playback (and possibly recording) is supported. No video-specific control interfaces are included.
  • Multiple players cannot be synchronized.
  • The DataSource class and the rest of the javax.microedition.media.protocol package are excluded; applications cannot provide their own protocol implementations.
  • The Manager class is simplified.

MIDP 2.0 requires support for tone generation and sampled .wav audio playback.

Summary

The Mobile Media API provides a compact, flexible, and clean API for using multimedia capabilities from a Java application running on a mobile device. At the time of this writing, the Mobile Media API is finished with its public review in the Java Community Process; expect a reference implementation release in the summer of 2002.

Thursday, March 12, 2009

J2ME

1. What is J2ME

Java 2 Micro Edition is a group of specifications and technologies that pertain to Java on small devices. The J2ME moniker covers a wide range of devices, from pagers and mobile telephones through set-top boxes and car navigation systems. The J2ME world is divided into configurations and profiles, specifications that describe a Java environment for a specific class of device.

2. What is J2ME WTK

The J2ME Wireless Toolkit is a set of tools that provides developers with an emulation environment, documentation and examples for developing Java applications for small devices. The J2ME WTK is based on the Connected Limited Device Configuration (CLDC) and Mobile Information Device Profile (MIDP) reference implementations, and can be tightly integrated with Forte for Java

6. What is CDC

The Connected Device Configuration (CDC) is a specification for a J2ME configuration. Conceptually, CDC deals with devices with more memory and processing power than CLDC; it is for devices with an always-on network connection and a minimum of 2 MB of memory available for the Java system.

11. What is cHTML

Compact HTML (cHTML) is a subset of HTML which is designed for small devices. The major features of HTML that are excluded from cHTML are: JPEG image, Table, Image map, Multiple character fonts and styles, Background color and image, Frame and Style sheet.

12. What is CLDC

The Connected, Limited Device Configuration (CLDC) is a specification for a J2ME configuration. The CLDC is for devices with less than 512 KB or RAM available for the Java system and an intermittent (limited) network connection. It specifies a stripped-down Java virtual machine1 called the KVM as well as several APIs for fundamental application services. Three packages are minimalist versions of the J2SE java.lang, java.io, and java.util packages. A fourth package, javax.microedition.io, implements the Generic Connection Framework, a generalized API for making network connections.

13. What is configuration

In J2ME, a configuration defines the minimum Java runtime environment for a family of devices: the combination of a Java virtual machine (either the standard J2SE virtual machine or a much more limited version called the CLDC VM) and a core set of APIs. CDC and CLDC are configurations. See also profile, optional package.

14. What is CVM

The Compact Virtual Machine (CVM) is an optimized Java virtual machine1 (JVM) that is used by the CDC.

16. What is EDGE

Enhanced Data GSM Environment (EDGE) is a new, faster version of GSM. EDGE is designed to support transfer rates up to 384Kbps and enable the delivery of video and other high-bandwidth applications. EDGE is the result of a joint effort between TDMA operators, vendors and carriers and the GSM Alliance.

20. What is Generic Connection Framework

The Generic Connection Framework (GCF) makes it easy for wireless devices to make network connections. It is part of CLDC and CDC and resides in the javax.microedition.io package.

21. What is GPRS

The General Packet Radio System (GPRS) is the next generation of GSM. It will be the basis of 3G networks in Europe and elsewhere.

22. What is GSM

The Global System for Mobile Communications (GSM) is a wireless network system that is widely used in Europe, Asia, and Australia. GSM is used at three different frequencies: GSM900 and GSM1800 are used in Europe, Asia, and Australia, while GSM1900 is deployed in North America and other parts of the world.

30. What is 3GPP

The 3rd Generation Partnership Project (3GPP) is a global collaboration between 6 partners: ARIB, CWTS, ETSI, T1, TTA, and TTC. The group aims to develop a globally accepted 3rd-generation mobile system based on GSM.

37. What is KJava

KJava is an outdated term for J2ME. It comes from an early package of Java software for PalmOS, released at the 2000 JavaOne show. The classes for that release were packaged in the com.sun.kjava package.

33. What is JCP

The Java Community Process (JCP) an open organization of international Java developers and licensees who develop and revise Java technology specifications, reference implementations, and technology compatibility kits through a formal process.

34. What is JDBC for CDC/FP

The JDBC Optional Package for CDC/Foundation Profile (JDBCOP for CDC/FP) is an API that enables mobile Java applications to communicate with relational database servers using a subset of J2SE's Java Database Connectivity. This optional package is a strict subset of JDBC 3.0 that excludes some of JDBC's advanced and server-oriented features, such as pooled connections and array types. It's meant for use with the Foundation Profile or its supersets.

35. What is JSR

Java Specification Request (JSR) is the actual description of proposed and final specifications for the Java platform. JSRs are reviewed by the JCP and the public before a final release of a specification is made.

38. What is kSOAP

kSOAP is a SOAP API suitable for the J2ME, based on kXML.

39. What is kXML

The kXML project provides a small footprint XML parser that can be used with J2ME.

40. What is KVM

The KVM is a compact Java virtual machine (JVM) that is designed for small devices. It supports a subset of the features of the JVM. For example, the KVM does not support floating-point operations and object finalization. The CLDC specifies use of the KVM. According to folklore, the 'K' in KVM stands for kilobyte, signifying that the KVM runs in kilobytes of memory as opposed to megabytes.

42. What is LCDUI

LCDUI is a shorthand way of referring to the MIDP user interface APIs, contained in the javax.microedition.lcdui package. Strictly speaking, LCDUI stands for Liquid Crystal Display User Interface. It's a user interface toolkit for small device screens which are commonly LCD screens.

43. What is MExE

The Mobile Execution Environment (MExE) is a specification created by the 3GPP which details an applicatio n environment for next generation mobile devices. MExE consists of a variety of technologies including WAP, J2ME, CLDC and MIDP.

44. What is MIDlet

A MIDlet is an application written for MIDP. MIDlet applications are subclasses of the javax.microedition.midlet.MIDlet class that is defined by MIDP.

45. What is MIDlet suite

MIDlets are packaged and distributed as MIDlet suites. A MIDlet suite can contain one or more MIDlets. The MIDlet suite consists of two files, an application descriptor file with a .jad extension and an archive file with a .jar file. The descriptor lists the archive file name, the names and class names for each MIDlet in the suite, and other information. The archive file contains the MIDlet classes and resource files.

46. What is MIDP

The Mobile Information Device Profile (MIDP) is a specification for a J2ME profile. It is layered on top of CLDC and adds APIs for application life cycle, user interface, networking, and persistent storage.

47. What is MIDP-NG

The Next Generation MIDP specification is currently under development by the Java Community Process. Planned improvements include XML parsing and cryptographic support.

48. What is Mobitex

Mobitex is a packet-switched, narrowband PCS network, designed for wide-area wireless data communications. It was developed in 1984 by Eritel, an Ericsson subsidiary, a nd there are now over 30 Mobitex networks in operation worldwide.

50. What is MSC

A Mobile Switching Center (MSC) is a unit within a cellular phone network that automatically coordinates and switches calls in a given cell. It monitors each caller's signal strength, and when a signal begins to fade, it hands off the call to another MSC that's better positioned to manage the call.

52. What is optional package

An optional package is a set of J2ME APIs providing services in a specific area, such as database access or multimedia. Unlike a profile, it does not define a complete application environment, but rather is used in conjunction with a configuration or a profile. It extends the runtime environment to support device capabilities that are not universal enough to be defined as part of a profile or that need to be shared by different profiles. J2ME RMI and the Mobile Media RMI are examples of optional packages.

53. What is OTA

Over The Air (OTA) refers to any wireless networking technology.

54. What is PCS

Personal Communications Service (PCS) is a suite of second-generation, digitally modulated mobile-communications interfaces that includes TDMA, CDMA, and GSM. PCS serves as an umbrella term for second-generation wireless technologies operating in the 1900MHz range

55. What is PDAP

The Personal Digital Assistant Profile (PDAP) is a J2ME profile specification designed for small platforms such as PalmOS devices. You can think of PDAs as being larger than mobile phones but smaller than set-top boxes. PDAP is built on top of CLDC and will specify user interface and persistent storage APIs. PDAP is currently being developed using the Java Community Process (JCP).

57. What is PDCP

Parallel and Distributed Computing Practices (PDCP) are often used to describe computer systems that are spread over many devices on a network (wired or wireless) where many nodes process data simultaneously.

58. What is Personal Profile

The Personal Profile is a J2ME profile specification. Layered on the Foundation Profile and CDC, the Personal Profile will be the next generation of PersonalJava technology. The specification is currently in development under the Java Community Process (JCP).

59. What is PersonalJava

PersonalJava is a Java environment based on the Java virtual machine1 (JVM) and a set of APIs similar to a JDK 1.1 environment. It includes the Touchable Look and Feel (also called Truffle), a graphic toolkit that is optimized for consumer devices with a touch sensitive screen. PersonalJava will be included in J2ME in the upcoming Personal Profile, which is built on CDC.

60. What is PNG

Portable Network Graphics (PNG) is an image format offering lossless compression and storage flexibility. The MIDP specification requires implementations to recognize certain types of PNG images.

63. What is preverification

Due to memory and processing power available on a device, the verification process of classes are split into two processes. The first process is the preverification which is off-device and done using the preverify tool. The second process is verification which is done on-device.

64. What is profile

A profile is a set of APIs added to a configuration to support specific uses of a mobile device. Along with its underlying configuration, a profile defines a complete, and usually self-contained, general-purpose application environment. Profiles often, but not always, define APIs for user interface and persistence; the MIDP profile, based on the CLDC configuration, fits this pattern. Profiles may be supersets or subsets of other profiles; the Personal Basis Profile is a subset of the Personal Profile and a superset of the Foundation Profile. See also configuration, optional package.

67. What is PSTN

The public service telephone network (PSTN) is the traditional, land-line based system for exchanging phone calls.

68. What is RMI

Remote method invocation (RMI) is a feature of J2SE that enables Java objects running in one virtual machine to invoke methods of Java objects running in another virtual machine, seamlessly.

69. What is RMI OP

The RMI Optional Package (RMI OP) is a subset of J2SE 1.3's RMI functionality used in CDC-based profiles that incorporate the Foundation Profile, such as the Personal Basis Profile and the Personal Profile. The RMIOP cannot be used with CLDC-based profiles because they lack object serialization and other important features found only in CDC-based profiles. RMIOP supports most of the J2SE RMI functionality, including the Java Remote Method Protocol, marshalled objects, distributed garbage collection, registry-based object lookup, and network class loading, but not HTTP tunneling or the Java 1.1 stub protocol.

70. What is RMI Profile

The RMI Profile is a J2ME profile specification designed to support Java's Remote Method Invocation (RMI) distributed object system. Devices implementing the RMI Profile will be able to interoperate via RMI with other Java devices, including Java 2, Standard Edition. The RMI Profile is based on the Foundation Profile, which in turn is based on CDC.

71. What is RMS

The Record Management System (RMS) is a simple record-oriented database that allows a MIDlet to persistently store information and retrieve it later. Different MIDlets can also use the RMS to share data.

73. What is SIM

A Subscriber Identity Module (SIM) is a stripped-down smart card containing information about the identity of a cell-phone subscriber, and subscriber authentication and service information. Because the SIM uniquely identifies the subscriber and is portable among handsets, the user can move it from one kind of phone to another, facilitating international roaming.

74. What is SMS

Short Message Service (SMS) is a point-to-point service similar to paging for sending text messages of up to 160 characters to mobile phones.

75. What is SOAP

The Simple Object Access Protocol (SOAP) is an XML- based protocol that allows objects of any type to communicated in a distributed environment. SOAP is used in developing Web Services.

77. What is T9

T9 is a text input method for mobile phones and other small devices. It replaces the "multi-tap" input method by guessing the word that you are trying to enter. T9 may be embedded in a device by the manufacturer. Note that even if the device supports T9, the Java implementation may or may not use it. Check your documentation for details.

79. What is Telematics

Telematics is a location-based service that routes event notification and control data over wireless networks to and from mobile devices installed in automobiles. Telematics makes use of GPS technology to track vehicle latitude and longitude, and displays maps in LED consoles mounted in dashboards. It connects to remote processing centers that turn provide server-side Internet and voice services, as well as access to database resources.

81. What is UDDI

Universal Description, Discovery, and Integration (UDDI) is an XML-based standard for describing, publishing, and finding Web services. UDDI is a specification for a distributed registry of Web services.

85. What is WAP

Wireless Application Protocol (WAP) is a protocol for transmitting data between servers and clients (usually small wireless devices like mobile phones). WAP is analogous to HTTP in the World Wide Web. Many mobile phones include WAP browser software to allow users access to Internet WAP sites.

86. What is WAP Gateway

A WAP Gateway acts as a bridge allowing WAP devices to communicate with other networks (namely the Internet).

87. What is W-CDMA

Wideband Code-Division Multiple Access (W-CDMA), also known as IMT-2000, is a 3rd generation wireless technology. Supports speeds up to 384Kbps on a wide-area network, or 2Mbps locally.

88. What is WDP

Wireless Datagram Protocol (WDP) works as the transport layer of WAP. WDP processes datagrams from upper layers to formats required by different physical datapaths, bearers, that may be for example GSM SMS or CDMA Packet Data. WDP is adapted to the bearers available in the device so upper layers don't need to care about the physical level.

89. What is WMA

The Wireless Messaging API (WMA) is a set of classes for sending and receiving Short Message Service messages. See also SMS.

90. What is WML

The Wireless Markup Language (WML) is a simple language used to create applications for small wireless devices like mobile phones. WML is analogous to HTML in the World Wide Web.

91. What is WMLScript

WMLScript is a subset of the JavaScript scripting language designed as part of the WAP standard to provide a convenient mechanism to access mobile phone's peripheral functions.

92. What is WSP

Wireless Session Protocol (WSP) implements session services of WAP. Sessions can be connection-oriented and connectionless and they may be suspended and resumed at will.

93. What is WTLS

Wireless Transport Layer Security protocal (WTLS) does all cryptography oriented features of WAP. WTLS handles encryption/decryption, user authentication and data integrity. WTLS is based on the fixed network Transport Layer Security protocal (TLS), formerly known as Secure Sockets Layer (SSL).

95. What is WTP

Wireless Transaction Protocol (WTP) is WAP's transaction protocol that works between the session protocol WSP and security protocol WTLS. WTP chops data packets into lower level datagrams and concatenates received datagrams into useful data. WTP also keeps track of received and sent packets and does re-transmissions and acknowledgment sending when needed.



Monday, March 9, 2009

C/C++ software memory corruption types: There are two forms of Linux Memory accessible to the programmer: 1. User's virtual memory space in which

C/C++ software memory corruption types:

There are two forms of Linux Memory accessible to the programmer:

  1. User's virtual memory space in which application is run.
  2. Register memory.

The most obvious memory errors result in a "Segmentation violation" message. This may alert the programmer to the location of the memory error when the program is run in gdb. The following errors discussed are the not so obvious errors.

Memory errors:

  • Heap memory errors:
    • Attempting to free memory already freed.
    • Freeing memory that was not allocated.
    • Attempting to write to memory already freed.
    • Attempting to write to memory which was never allocated.
    • Memory allocation error.
    • Reading/writing to memory out of the bounds of a dynamically allocated array

  • stack (local variables) memory errors:
    • Reading/writing to memory out of the bounds of a static array. (array index overflow - index too large/underflow - negative index)
    • Function pointer corruption: Invalid passing of function pointer and thus a bad call to a function.


Memory Leaks:

Memory leak description: Memory is allocated but not released causing an application to consume memory reducing the available memory for other applications and eventually causing the system to page virtual memory to the hard drive slowing the application or crashing the application when than the computer memory resource limits are reached. The system may stop working as these limits are approached.


Many C library functions malloc's memory which MUST be freed: i.e.: strdup(),

#include 
#include

...

char *oldString = "Old String";
char newStrig = strdup(oldString);
if(newString == ENOMEM) ... // Fail!!!!

...

free(newString);
Note: You can NOT use the C++ delete call. The strdup() function is part of the C library and you must use free().

Any routine which is supplied by the C libraries or ones written within an application which allocate memory must have the memory freed. Comments on this need should be included in the include file to make users of the function aware of their duties to free the memory and the mechanism by which it is to be freed (free() or delete).


Programmer must free() malloc()'ed memory:

Also for calloc(), malloc() and realloc();

#include 

char *textString = malloc(128*sizeof(char));
if(textString == ENOMEM) ... // Fail!!!!
...
free(textString); // Don't free if allocation failed

Check for memory allocation errors. Can't free it if it didn't get allocated.


Programmer must delete new'ed memory:

using namespace std;

ptr = new ClassTypeA;

...

delete ClassTypeA;
New/delete is preferred to malloc()/free() because it can initialize the memory and it invokes the constructor for new objects. New/delete also point to the correct memory type. Note on mixing source code containing new/delete and malloc()/free(). This is not a problem with the GNU C++ compiler but this is not guaranteed for all C++ compilers.


Inheritance, polymorphism and the wrong delete:

BaseClass* obj_ptr = new DerivedClass;  // Allowed due to polymorphism.
...
delete obj_ptr; // this will call the destructor ~Parent() and NOT ~Child()

If you are counting on the destructor to delete memory allocated in the constructor beware of this mistake as it will cause a memory leak. Use a virtual destructor to avoid this problem. The ~BaseClass() destructor is called and then the destructor ~DerivedClass() is chosen and called at run time because it is a virtual destructor. If it is not declared virtual then only the ~BaseClass() destructor is called leaving any allocated memory from the DerivedClass to persist and leak. This assumes that the DerivedClass has extra memory allocated above and beyond that of the BaseClass which must be freed.

The same ill effect can be achieved with a C style cast to a class of less scope which will dumb down the destructor to that which may not execute all the freeing of the original class. A C++ style dynamic cast may prevent this error as it will recognize the loss of translation and not allow the cast to take place resulting in a traceable crash rather a tough to find memory leak.


Pointer re-assignment error leads to dangling pointer:

If the pointer is re-assigned a new value before being freed, it will lead to a "dangling pointer" and memory leak.

Example:

char *a = malloc(128*sizeof(char));
char *b = malloc(128*sizeof(char));
b = a;
free(a);
free(b); // will not free the pointer to the original allocated memory.


Default copy constructor may not give correct results:

Memory allocated by copy constructors for pointer duplication. Check in destructor and delete if necessary. Memory allocated in passing class by value which invokes copy constructor. Also beware, the default copy constructor may not give you the results you want especially when dealing with pointers as the default copy constructor has no knowledge of how to copy the contents of what the pointer points to. To prohibit the use of the default copy constructor define a null assignment operator.

ClassA& operator=(const ClassA& right_hand_side);


Good practice: Use assert to check pointers before freeing or using:

assert(ptr !=0)


Memory Corruption:

Memory Corruption: Memory when altered without an explicit assignment due to the inadvertent and unexpected altering of data held in memory or the altering of a pointer to a specific place in memory.


Buffer overflow:

Example 1:
Overwrite beyond allocated length - overflow.

char *a = malloc(128*sizeof(char));
memcpy(a, data, dataLen); // Error if dataLen too long.

Example 2:
Index of array out of bounds: (array index overflow - index too large/underflow - negative index)

ptr = (char *) malloc(strlen(string_A));  // Should be (string_A + 1) to account for null termination.
strcpy(ptr, string_A); // Copies memory from string_A which is one byte longer than its destination ptr.
Overflow by one byte.


Using an address before memory is allocated and set:

struct *ABC_ptr;
x = ABC_ptr->name;
In this case the memory location is NULL or random.


Using a pointer which is already freed:

char *a = malloc(128*sizeof(char));
..
..
free(a);

cout << a << endl; // This will probably work but dangerous.

... Do stuff. Probable overwriting of freed memory.

cout << a << endl; // No longer the same contents. Memory overwritten by new stuff.


Freeing memory which has already been freed. Also applies to delete.

Freeing a pointer twice:

char *a = malloc(128*sizeof(char));
free(a);
... Do stuff
free(a); // A check for NULL would indicate nothing.
// This memory space may be reallocated and thus we may be freeing
// memory we do not intend to free or portions of another block of
// memory. The size of the block of memory allocated is often held
// just before the memory block itself..

Freeing memory which was not dynamically allocated:

struct ABC abc;
struct ABC *abc_ptr = &abc;
...
free(abc_ptr);


Incorrect use of delete: The delete must match the use of new.

The pairing is new/delete and new [] / delete[]

ClassABC *abc_ptr = new ClassABC[100];
...
delete [] abc_ptr;
Use of "delete abc_ptr" is an error.

Do not use malloc()/free() with a C++ class as it will not call the constructor or destructor. Also malloc()/free() can not be mixed with new/delete. i.e. Free() can not be used to free memory allocated with new and delete can not be used to free memory allocated with malloc().


Exception Errors:

Freeing memory never allocated. If you use a constructor to allocate memory but an exception is thrown before all is allocated, the destructor needs to be aware that fact or else it may try to free memory which was never allocated.

Also the converse is true. If the destructor throws an exception, subsequent steps which free memory may not be executed. This applies to the destructor and all nested destructors which handle/re-throw the exception while the stack unwinds.


Pointer persistence:

Function returning a pointer from the stack which can get overwritten by the calling function (in this case main()):

int *get_ii()
{
int ii; // Local stack variable
ii = 2;
return ⅈ
}
main()
{
int *ii;
ii = get_ii(); // After this call the stack is given up by the routine
// get_ii() and its values are no longer safe.

... Do stuff
.. ii may be corrupt by this point.
}
This is also true for a local variable within the scope of only { and } as well as for the scope of a function.


Incorrect passing of a function argument:

If the pointer is passed around as an argument and does not get passed correctly, one may try to free the incorrect pointer.


Mixing the object base class and derived class:

If mixing the object base class and derived class when passing an object by value as a function parameter, make sure that you understand what may be lost.

function_A(BaseClass baseClass_ptr)
{
...
}

// Call to function
function_A(derivedClass_ptr); // Note that much of the information contained
// in the derived class will not be passed into
// the function including virtual destructors.


Copying an object:

Don't use memcpy() or any bit for bit copy function to copy an object. It will not execute the class constructor. What kind of person would do this?? Passing an object in a va_arg() list will result in a bit for bit copy and will not use the default copy constructor.


Links:

Related YoLinux Tutorials:

Friday, March 6, 2009

Interview questions

1) What's the difference between fopen and open?
fopen/fread/fwrite have buffer to fasten I/O process, but open/read/write
dosen't

open() is not standard and might not be implemented in some standard-conforming hosted environments, whereas fopen() is standard and is implemented in all standard-conforming hosted environments. Therefore for portability, use the standard functions, not (emulated)
Unix system service calls.

There are other functional differences, the most notable being that the stdio stream uses a buffer in "user space", whereas the direct system-call I/O does not. (There might or might not be kernel-space buffers in both cases.) This can matter if record length is important; for example, if you want to write a magnetic tape record of length 80, write(fd,buf,80) will do that, whereas fwrite(buf,80,1,fp) will likely just put the data in a user-space buffer, with the actual write occurring eventually when the buffer is full - which will result in something like a 512-byte
magtape record. You could perhaps work around that by issuing a fflush(fp) after the fwrite(), but it's a kludgy way to accomplish what write() does directly.

2) Difference between Threads and process

A single process can have multiple threads that share global data and address space with other threads running in the same process, and therefore can operate on the same data set easily. Processes do not share address space and a different mechanism must be used if they are to share data.
If we consider running a word processing program to be a process, then the auto-save and spell check features that occur in the background are different threads of that process which are all operating on the same data set (your document).

Creation of new process requires new resources and Address space whereas the thread can be created in the same address space of the process which not only saves space and resources but are also easy to create and delete,and many threads can exhists in a process.

Threads share the address space of the process that created it; processes have their own address.

Threads have direct access to the data segment of its process; processes have their own copy of the data segment of the parent process.


Threads can directly communicate with other threads of its process; processes must use inter-process communication to communicate with sibling processes.

Threads have almost no overhead; processes have considerable overhead.

New threads are easily created; new processes require duplication of the parent process.

Threads can exercise considerable control over threads of the same process; processes can only exercise control over child processes.

Changes to the main thread (cancellation, priority change, etc.) may affect the behavior of the other threads of the process, changes to the parent process does not affect child processes.


Both have an id, set of registers, state, priority, and scheduling policy.

Both have attributes that describe the entity to the OS.

Both have an information block.

Both share resources with the parent process.

Both function as independent entities from the parent process.

The creator can exercise some control over the thread or process.

Both can change their attributes.

Both can create new resources.

Neither can access the resources of another process.


3) Difference between mutex and critical section

A concrete example of program using a mutex between process, is the registry (advapi32.dll).

All registry operations use the same mutex to modify the internal hash-table that represents the registry (Under Windows 95 and 98 at least).

So remember (on multiprocessor platform at least) that a registry function is relatively slow.

I think that CriticalSections use internally a Semaphore, and that a request to a critical section is very, very fast if the critical section if not currently used (for many applications, that is almost always the case), and if not it is slow like a normal mutex or semaphore.

Quite often you'll see reference to the speed differences between the user mode critical section and the kernel objects mutex and semaphore. I really don't pay much attention to these 'speed' differences because either you can use a critical section or you can't.

If you are synchronizing data shared between multiple threads of the same process, you can use a critical section. Yes, you *could* use a mutex or semaphore, but they will be a few clock cycles slower because they are kernel objects. A good general usage rule is: When in the same process, prefer to use the critical section.

When you are synchronizing data shared between multiple processes, you can't use a critical section. So it doesn't matter that the mutex or semaphore is slower than the critical section, since you can't use a critical section anyway across processes.

I usually follow this rule: "Slower, properly synchronized data is still better than fast, corrupt data!"

A critical section object provides synchronization similar to that provided by a mutex object, except that a critical section can be used only by the threads of a single process. Event, mutex, and semaphore objects can also be used in a single-process application, but critical section objects provide a slightly faster, more efficient mechanism for mutual-exclusion synchronization (a processor-specific test and set instruction). Like a mutex object, a critical section object can be owned by only one thread at a time, which makes it useful for protecting a shared resource from simultaneous access. Unlike a mutex object, there is no way to tell whether a critical section has been abandoned.