ACE Server programming 2: ACE cross-platform data type and width character, ace Server

Source: Internet
Author: User

ACE Server programming 2: ACE cross-platform data type and width character, ace Server

One of the main advantages of the ACE network library is cross-platform. ACE provides a cross-platform solution at the operating system API and compiler level, so that developers do not have to worry about the differences between the operating system and the compiler, but it also brings about the complexity of ACE.

The organizational structure of the ACE network library consists of four layers: OS adaptation layer, wrapper facade layer, framework layer, and service layer. The OS adaptation layer provides packaging functions for operating system APIs, this ensures system-level cross-platform features.

Different C ++ compilers also have obvious differences in the following aspects:

1. templates;

2. Data Type and width;

3. Initialization and shutdown during running;

4. Allocate heap memory;

The above is mainly based on the content in the APG, but the APG is somewhat outdated. For example, ACE_ OS mentioned in this section uses classes to prevent the compiler from supporting namespaces, in the new version of ACE, namespace implementation has been changed.

This article mainly discusses the cross-platform ACE solution for data types and wide characters. Based on ACE 6.0, for how to compile ACE, see http://www.cnblogs.com/ym123/p/4277256.html:

Data Type

The basic data of different C ++ compilers is different, which is usually solved by pre-defined types. This is also a common C ++ technique.

ACE also defines common basic types:

ACE_INT8, ACE_INT16, ACE_INT32, ACE_INT64, unsigned ACE_UINT8, ACE_UINT16, ACE_UINT32, ACE_UINT64;

At the same time, ACE also provides the definition of SIZEOF, so that you can easily obtain the length of this type in the compiler:

ACE_SIZEOF_LONG, ACE_SIZEOF_INT, ACE_SIZEOF_CHAR...

ACE also provides definitions of tail and tail:

The value of ACE_BYTE_ORDER is ACE_BIG_ENDIAN or ACE_LITTLE_ENDIAN;

If the size of the data type is important to your program, you should not rely on the hardware size of the compiler but use these basic types. For example, it is common to determine the header size of the TCP packet content length, the length should be specified.

These types are defined in the ace/Basic_Types.h header file.

Narrow and wide characters

ACE defines two constants:

ACE_HAS_WCHAR is used to enable ACE wide character configuration;
ACE_USES_WCHAR indicates that ACE uses the width character configuration internally.

These two constants work when compiling the ACE network library. If you want to use wide characters, enter:

# Define ACE_HAS_WCHAR

# Define ACE_USE_WCHAR

ACE defines the ACE_TCHAR type and uses char or wchar_t according to ACE_USES_WCHAR;

ACE_TEXT (str), which correctly defines the string text according to ACE_USES_WCHAR;

ACE_TEXT_CHAR_TO_TCHAR (str). If necessary, convert char * To ACE_TCHAR;

ACE_TEXT_WCHAR_TO_TCHAR (str). If necessary, convert wchar_t * To ACE_TCHAR;

ACE_TEXT_ALWAYS_CHAR (str). If necessary, convert ACE_TCHAR to char *;

ACE defines the ACE_CString and ACE_WString types, and the access narrow string and wide string. The specific usage is similar to the std: string type, which is defined in the ace/SString. h header file.

The implementation of ACE to solve the differences among the other three compilers will be explained in the subsequent blog.

Record, for better yourself!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.