anydac mysql_RAD Studio XE2 Tips

http://www.da-soft.com/blogs/anydac-for-delphi-and-rad-studio-xe2.html

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

a4c26d1e5885305701be709a3d33442f.png

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:

Type

DCC32

DCC64

Integer,

LongWord,

Cardinal

4

4

Int64,

UInt64

8

8

NativeInt,

NativeUInt

4

8

Pointer

4

8

THandle

4

8

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

Exception handling. Delphi x64 employs different exception

handling mechanisms, than Delphi x32. More about that - Uwe

Schuster Blog, RAD Studio XE2: Win64 exceptions and stack traces

on Win64 (JCL/JVCL 64) and OS X. Delphi x64 has limitation -

maximum 16 levels of nesting exceptions:

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.

a4c26d1e5885305701be709a3d33442f.png

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.

a4c26d1e5885305701be709a3d33442f.png

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.

a4c26d1e5885305701be709a3d33442f.png

Running

Not much to say, just to run Task Manager and see that the

application is really 64-bit:

a4c26d1e5885305701be709a3d33442f.png

AnyDAC

Availability

a4c26d1e5885305701be709a3d33442f.png

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:

a4c26d1e5885305701be709a3d33442f.png

The x64 results:

a4c26d1e5885305701be709a3d33442f.png

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值