Additional
AnyDAC for Delphi and RAD Studio XE2
Posted by Support [Aug 28, 2011]

AnyDAC for Delphi 5.0.3 will support RAD Studio XE2. This first article shows differences between x32 and x64 compilation modes, how to setup Delphi x64, how to configure AnyDAC for x64, what benefits and performance you will get. All, what you need to know about Delphi x64 / AnyDAC.



RAD Studio XE2

World Tour

At first, the RAD Studio XE2 is here ! After filtering many marketing words around the release, you will see, that almost nothing has been filtered. That is really great Delphi release for many years, even greater than Delphi 2009 (Unicode) and Delphi 2005 (new IDE). It is like Delphi 2 (Win32), but even more greater ! Some new features:

 

  • Windows x64 compiler - dcc64.exe;
  • Mac OS x32 compile - dccosx.exe;
  • Live Data Binding;
  • FireMonkey platform.

 

To learn more about RAD Studio XE2 you are invited to the World Tour !

 

  

General

There are some major differences between x32 and x64 compilation modes. Actually, some data types behaves differently. Also, there are some changes and consequences to the Delphi RTL and base classes. All that may require to review and update your existing code before compiling it for x64.

 

RAD Studio XE2 IDE itself is a 32 bit application. All design time packages are 32 bit too. You design the application and code the logic behind the way you are used too. The difference will start at compiling and may require to set additional options. To produce x64 application the dcc64.exe is used.

Language, RTL, VCL Changes

When developing a code you should be aware of the following differences in language and RTL between Delphi x32 and x64 compiling modes. And also about incorrect expectations.

 

  • Integer and Pointer data types. The data type sizes may be different:

 

 TypeDCC32 DCC64 
Integer,
LongWord,
Cardinal
44
Int64,
UInt64
88
NativeInt,
NativeUInt 
48
Pointer 48
THandle 48

 

  • Floating point data types. Extended is a synonym to Double in x64 mode (but see TExtendedX87). The compiler codegen produces SSE2 instructions instead of FPU. That dramatically improves performance of numeric intensive applications !
  • Compilers defines. The following symbols (some interesting) are defined:

 

DCC32 

DCC64 

CPU386
CPUX86
WIN32
MSWINDOWS
VER230
UNICODE

CPUX64
WIN64
MSWINDOWS
VER230
UNICODE

 

    try
      ...
      raise 
    except
      on E1: Exception do
        try
          ...
          raise 
        except
          on E2: Exception do
            // 14 more nested try / except / raise - OK
            // 15'th will lead to AV
        end;    
    end;

  • Calling conventions. Delphi x64 supports only single calling convention - Microsoft x64 calling convention (first 4 parameters passed on rcx/xmm0; rdx/xmm1, r8/xmm2, r9/xmm3). All other conventions, like stdcall, pascal are synonyms for this one.
  • In x64 NativeInt / NativeUInt for-loop index variable is more effective than Integer one:

    var
      i: NativeInt;
    ...
    for i := 0 to N do ...;

  • ASM. Well ... x64 ASM is different - all stuffs must be recoded.
  • Strings. String, UnicodeString, AnsiString are still limited to 2Gb.
  • Dynamic arrays. Are limited to 2G of elements on x32 and to 4T of elements on x64.
  • TList. Is still limited to 2G of elements. The same applies to other classes build around TList - TStringList, multiple classes in System.Contnrs.pas and System.Generics.Collections.pas units, etc.
  • TComponent. The Tag property is NativeInt.
  • Ohh, yes ... There is no more BDE ! It is left in the 32 bit world. One more reason to migrate to AnyDAC.

Setting Options

To compile AnyDAC x64 application, you will need to enable x64 platform for the project and make the platform current. For that:

 

  • show "Project Manager";
  • select "Target Platforms" node;
  • right click on it and choose "Add Platform";
  • select 64-bit Windows platform and press OK.

 

 

You may optionally check / add / update Library Path for x64 platform. Note, that paths are different for different platforms. For that:

 

  • choose Tools -> Options;
  • locate Environment Options -> Delphi Options -> Library;
  • on the top right combo box choose "64-bit Windows";
  • adjust paths as needed.

 

 

Then you may adjust your project options. For that:

 

  • choose Project -> Options;
  • on the top right combo box choose a right combination of configuration and platform;
  • adjust options as needed. 

Compiling

Now you can compile and run your AnyDAC application. All IDE keyboard shortcuts, menu items are the same as for 32 bit.

 

To compile in command line you have to use DCC64.EXE compiler. It has practically the same command line switches as DCC32.EXE. The default configuration file is DCC64.CFG.

Debugging

Debugging is a bit different. The IDE is 32 bit. An application is 64 bit. So, the IDE does no longer host the 64 bit debugger. The debugging process is remote and the dbkw64_16_0.exe serves as x64 debugging server. To make that possible you have to enable remote debug symbols. Hopefully IDE will enable it automatically for pre-XE2 projects. For that:

 

  • choose Project -> Options;
  • on the top right combo box choose "Debug configuration - 64-bit Windows platform";
  • locate "Delphi Compiler" -> "Linking";
  • mark "Include remote debug symbols" ON.

 

Running

Not much to say, just to run Task Manager and see that the application is really 64-bit:

 

AnyDAC

Availability

 

AnyDAC for Delphi Trial and Beta versions 5.0.2 are accessible from there. The final 5.0.3 will be released shortly after RAD Studio XE2 release date.

 

AnyDAC beta version is accessible only to registered users with active AnyDAC subscription.

 

AnyDAC trial version contains only 32 bit binaries. You can design and develop your AnyDAC application with trial version as for x32, as for x64. But to compile and run your applcation, you will need the full AnyDAC version.

 

AnyDAC full version may be purchased for $399 from there. The 1 year subscription allows to purchase AnyDAC for Delphi today and receive all new versions releasing in 1 year !

Changes

What we changed in AnyDAC to make it x64 compatible:

 

  • were introduced many generic data types to enable simplified support of x32 and x64 platforms for Delphi and FPC / Lazarus. For example:

  {$IFDEF AnyDAC_64}
    {$IFDEF AnyDAC_POSIX}
    TADULongInt = UInt64;
    {$ELSE}
    TADULongInt = LongWord;
    {$ENDIF}
  {$ELSE}
    TADULongInt = LongWord;
  {$ENDIF}
 
  {$IFDEF AnyDAC_D12}
    TADNativeInt = NativeInt;
  {$ELSE}
    {$IFDEF AnyDAC_64}
    TADNativeInt = Int64;
    {$ELSE}
    TADNativeInt = Integer;
    {$ENDIF}
  {$ENDIF}
 
  TADCounter = {$IFDEF AnyDAC_64} Int64 {$ELSE} LongInt {$ENDIF};

  • reviewed a lot of places with pointer arithmetic. A lot of changes like the following, from:

    Pointer(LongWord(ABuffer) + AOffset)

to

    Pointer(TADNativeUInt(ABuffer) + AOffset)

  • all ASM stuffs were replaced with highly optimized Delphi code. That will allow later to use AnyDAC on non-Intel platforms too.
  • all DBMS API headers translated into uADPhysXxxCLI.pas units were updated to enable x64 support. For example uADPhysMySQLCli.pas, from:

    MYSQL_FIELD0510 = record
      ........
      length:           LongWord; // Width of column
      max_length:       LongWord; // Max width of selected set
      ........
    end;

to:

 

    my_ulong      = TADULongInt;
 
    MYSQL_FIELD0510 = record
      ........
      length:           my_ulong; // Width of column
      max_length:       my_ulong; // Max width of selected set
      ........
    end;

  • some Integer and LongWord properties were re-typed to Int64 and UInt64 to enable usage of DBMS x64 features. For example, TADQuery property:

    property RowsAffected: TADCounter read FRowsAffected;

  • some method parameters used to transfer "generic" data were re-type like the following, from:

    procedure Notify(AKind: TADDatSNotificationKind;
      AReason: TADDatSNotificationReason; AParam1, AParam2: LongInt); overload;

to:

    procedure Notify(AKind: TADDatSNotificationKind;
      AReason: TADDatSNotificationReason; AParam1, AParam2: TADNativeInt); overload;

  • new driver configuration parameters were added. See details later in the text.
  • the environment reporting was updated to diagnose x64 specific issues.
  • some other minor changes were made.

DBMS Clients

Most of the DBMS vendors already provide x64 client libraries. They must be installed to make AnyDAC x64 application working and connecting to a DB. When x64 client is not installed, and even when x32 client is installed, then an exception will be raised. More about that.

 

For example, the Oracle Windows x64 Instant Client may be downloaded from there. When x64 client is not installed, then will be raised:

[AnyDAC][Phys][Ora]-1309. OCI is not properly installed on this machine (NOE1/INIT)

 

AnyDAC SQLite driver supports encryption only in static linking mode. At moment (5.0.3) in x64 mode only dynamic linking is supported. So, in x64 mode encryption is not accessible. AnyDAC installer installs on Windows x64 two sqlite3.dll versions:

 

  • x32 into SysWOW64 (v 3.7.7.1);
  • x64 into System32 (v 3.6.23.1).

Configuring AnyDAC drivers

The AnyDAC driver configuration file format was changed to add support for Windows x64 and other platforms. Now VendorHome and VendorLib parameters may have platform specific suffix. And there may be specified few VendorXxx parameters for different platforms. More about that.

 

For example, to configure AnyDAC Firebird driver you may use:

[IB]
BaseDriverID=IB
VendorLibWin32=E:\ib\fb25\bin\fbclient.dll
VendorLibWin64=E:\ib\fb25_x64\bin\fbclient.dll 

Other example for Oracle driver:

[Ora]
BaseDriverID=Ora
VendorHomeWin32=Ora11_32
VendorHomeWin64=Ora11_64 

 

The TADPhysXxxxDriverLink components have only single VendorHome and VendorLib property versions. These property values will be used for the compiled platform. The same with VendorHome and VendorLib parameters without a suffix in driver configuration file. For example:

ADPhysMySQLDriverLink1.VendorLib := 
    {$IFDEF WIN64} 'c:\MySQL\5.5_64\Bin\libmysql.dll' {$ENDIF}
    {$IFDEF WIN32} 'c:\MySQL\5.5\Bin\libmysql.dll' {$ENDIF};

Performance

Here are the benchmark results for AnyDAC TADMemTable and TClientDataSet. The benchmark is performed in x32 and x64 modes on laptop with AMD Phenom II 1.8GHz, 4Gb and Windows 7 x64. Each test processes 20k of records.

 

The x32 results:

 

The x64 results:

  

 

The benchmark shows that x32 code is about 10-30% more faster. So, for the classic data access applications the x32 is OK. The similar results we have for the AnyDAC Oracle driver.

Pros and Cons

The benefits an AnyDAC x64 application may get comparing to x32:

 

  • load into memory the BLOB values greater than 2Gb. Worth to have.
  • load into memory more than 0.5G of records. Hard to imagine.
  • the affected rows count may be more than 4G. Could be.
  • the total consumed memory may be greater than 2Gb. Could be.
  • improved numeric performance. Not for an average AnyDAC app, really.

 

The drawbacks are:

 

  • slightly less performance.
  • no SQLite encryption.

 

Combining all above with the own application needs for x64 will give you the correct vision - do you need or not the x64.

Conclusion

The x64 support is awaiting for a long time. And finally it is here ! Should you migrate your applications to x64 or not - depends on the application requirements.

 

Great that the Delphi supports more and more platforms ! We at DA-SOFT Technologies plan to support all the Delphi platforms and new technologies, like FireMonkey and Live Data Binding.

 

Further we will discuss the Live Data Binding. Stay tuned !

More to read

  1. Dmitry Kuzmenko Blog, 64 bit Delphi. Who needs it?

LIST OF COMMENTS


1/6. Buy now
Posted by Alex - Aug 30, 2011
Website

If i will purchase Anydac today, will i get 5.03 with xe2 support ?


2/6. RE: Buy now
Posted by Support - Aug 30, 2011
Website
When you purchase AnyDAC, you get not a specific version, but a 1 year subscription. So, you will get all product updates during the year. Means, if you will purchase AnyDAC today, you will get the current version and 1-2 weeks later you will get AnyDAC 5.0.3.

3/6. RE: Buy now
Posted by Alex - Aug 30, 2011
Website
Thanks. Any discounts ?

4/6. RE: Buy now
Posted by Support - Aug 30, 2011
Website
Please, contact sales at da-soft dot com

5/6. Mrman
Posted by kkkktest - Sep 03, 2011
Website
Do you support OSX w Delphi XE2?

6/6. RE: Mrman
Posted by Support - Sep 03, 2011
Website
The sources already may be compiled for Mac OS X with 5.0.2 beta. We still working on some integration / configuration issues.

Add Comments