Talk about Delphi VS VC ++

zhaozj2021-02-11  227

Casually come to find a file, but found that the discussion of VC and Delphi is very intense. I have seen some of you.

Article, I feel that some opinions are correct, some are very biased or even mistaken (maybe I don't know? I am sorry I said :-). I

Inadvertently arguing with anyone, it is more willing to see this as a technical discussion. Should be a fair, no prejudice attitude

(This does not mean that it is necessary to score autumn, everything should be truthful). I have used all the versions other than TP1

Turbo Pascal, all versions of Turbo C / Borland C , all versions of Delphi and C Builder;

And MSC 5.0 / 6.0, MSC / C 7.0 and Visual C 4.2 / 5.0. Don't say how high, at least

There is a little experience. Let's talk about my opinion.

Compiler

It should be said that Borland's compiler is best. Because Borland has the best compiler development group worldwide (although

Anders Hejlsberg leaves). From a technical point of view, Borland leads the competitors for at least 2 to 3 years. One

As a result, Borland's compiler can always generate smaller code and usually (not in any case) faster

Code.

Zi Yunying, Zengdeng said that VC compiled in the article, which is actually the result of dynamic connection. M $

The VC running library (MSVCRT * .dll, MSVCP * .dll, mfc * .dll, how much is these files added together)

When you install Windows, you are in the System / System32 directory. Two questions that "negotiate interface", fear

I am afraid that it is wrong to understand some English articles. M $ is not willing to run files on other companies in Windows,

There is no technical reason.

In fact, Delphi / C Builder is comparable to the generated procedures in the event of a dynamic connection or static connection.

Small VC . For example, an example of MDI: New ... | Projects in Delphi / C Builder ... | Projects |

MDI Application, using MDI App Wizard in VC ; generated program function is very similar.

The following is the comparison result:

(Delphi open optimization, C Builder use maximum speed optimization, VC 5 optimization using the minimum code)

Delphi 3 Delphi 5 C Builder 5 VC 5

Dynamic Link 21K 35K 44K 70K

Static Link 253K 398K 467K 490K

Any program that uses the application class library (regardless of MFC, OWL, VCL, and new CLX frameworks) are more than not used.

A lot. This is because the current smart link technology can only target global variables / processes, not

Used for object structure. Even if you only use an attribute or method of a class (or indirectly by this class), this

Class and all classes it are all connected to EXE. All compilers have not solved this question.

question.

(PS: Actually generating the minimum code (really compiled) high-level language compiler is Turbo Pascal, do not believe you write the program

Comparison:

PROGRAM TEST;

Begin

Writeln ('Hello, World.');

End.

The resulting EXE is less than 1.5K. The same C procedure:

#include

Main ()

{

Printf ("Hello, World./N");

The code generated by the most sophisticated C / C compiler is also 6K.

)

So what is the quality of the code generated by several compilers?

For example, for example, the For loop statement often used in programming:

(1) Object Pascal:

PROCEDURE FOO;

VAR

I, J: Integer;

Begin

For i: = 0 to 15 DO J: = J I;

END;

(2) C

Void foo (void)

{

INT I, J;

For (i = 0; i <16; i ) j = j i;

}

Delphi 3 generated code (open optimization): byte clock cycle

00424AA9 33C0 XOR EAX, EAX 1

00424AAB 40 Inc EAX 1

00424AAC 83F810 CMP EAX, 0x10 1

00424AF 75FA JNZ -0x06 0 (in parallel)

-----------------

8 3

C Builder 5 generated code (maximum speed optimization):

00401535 33c0 xor EAX, EAX 1

00401537 40 Inc EAX 1

00401538 83F810 CMP EAX, 0x10 1

0040153B 7CFA JL-0X06 0 (in parallel)

-----------------

8 3

Visual C 5 generated code (maximum speed optimization):

27: for (i = 0; i <16; i )

00401205 MOV ECX, DOWRD PTR [J] 1

00401208 xor Eax, EAX 0 (can be parallel)

28: {

29: j = j i;

0040120A Add ECX, EAX 1

0040120C Inc EAX 1

0040120D CMP EAX, 10H 1

00401210 jl foo (0x0040120a) 0ah 0 (in parallel)

00401212 MOV DWORD PTR [J], ECX 0/1 (depending on the branch prediction of the previous instruction)

30:};

-----------------

16 4.2 (Assuming that branch prediction accuracy is 80%)

The minimum code optimization of VC 5 also has 11 bytes:

27: for (i = 0; i <16; i )

00401205 XOR EAX, EAX 1

28: {

29: j = j i;

00401207 Add DWORD PTR [J], EAX 1

0040120A Inc EAX 10040120B CMP Eax, 10h 1

0040121E jl foo (0x00401207) 7 0 (in parallel)

30:};

-----------------

11 4

Note:

(1) The result of Delphi / C Builder is to use Turbo Debugger directly disassembled, and the result of VC 5 is from

Source-level debugging in the integrated environment.

(2) The number of clock cycles is taken as a Pentium processor. In fact, for the CPU without parallel execution units (such as

386/486 and NX586, etc.) The code speed generated by VC 5 is slower.

(3) Branch prediction accuracy derived from Intel's "Pentium Optimization Reference". But with specific procedures

The order is closely related, in general, the closer transfer command in the program is, the lower the branch prediction accuracy.

It can be seen that this program of Delphi / C Builder has an advantage of 1 to 1.2 clock cycles. This is mainly because

Delphi / C Builder compiler is more intelligent, and it is not compiled.

(Interestingly, for this program, the maximum speed optimization of VC 5 is not as good as the minimum code optimization.

The code is running fast. )

Don't think that 1 ~ 1.2 clock cycles are not countless, the fastness of the entire program is the accumulation of such a clock cycle.

from. And for these instructions, it is very expensive to 25% to 28.6%, which is a very considerable number.

I didn't use VC 6 test (I no longer use VC from VC 5, because C Builder 5 can be fully compatible

Vc --- This compatibility starts from C Builder 3, but it is not perfect, don't know if

There is improved. If someone is interested, please test it.

If you are interested, you can go to Jake's Code Efficiency Challenge (http://www.xnet.com/~johnjac)

Take a look. The code is running performance challenge. At present, Delphi / C Builder maintains 5 leaders in 6 tests.

(PS: Delphi 2 defeated VC 4.2 in performance test of PC Week in 1996)

2. Language features

First of all, I don't want to evaluate the so-called "Pascal is a toy language" this ignorance. Some Basic is not used

People are impossible to evaluate the advantages and disadvantages of other languages ​​correctly. As for "only high school students", it is more smile:

Peter Norton didn't go to college, ID Software's John Carmack did not go to college, you don't accept it? !

Please don't laugh at high school students, most of the programmers may never reach these "high school students". Creative

It is a genius. Do you think genius is equivalent to something? :-)

(1) Pretreatment, macro, and .h file

Object Pascal does not support pre-processing, in fact, it is not necessary. The compiler that cannot be directly compiled in the source code is required.

Support for processors (for translation / specification source (also included .h) to facilitate compilation). The emergence of the preprocessor is

Because the Ken Thompson and Dennis Ritchie are difficult to implement the C compiler on the PDP-11 with only 256K memory

A compromised approach taken very much. Modern C / C products have included the preprocessor in the compiler.

(PS: C whose keyword / operator is used in PS: C is also due to this historical reason)

As for Macro and .h, it should be said to be garbage, but it is only reserved due to compatibility considerations. ANSI / ISOC / C specification is clearly suggested: "Do not use macro and .h, you should use the constant definitions and functions in the program.

Generation. "Because Macro and .h is not the language characteristics of C / C (this is true!), There is no clear unified syntax definition.

It also causes the compilation speed to decrease, and the Macro is deployed in each place in each used, a large number of

Use Macro to bloated the generated code.

(2) Collection, subcord type

C does not support these Object Pascal native types (compilers can directly recognize). But you can use class to simulate,

After all, the object structure of C is the most complex flexible (except ADA). However, performance has lost.

(3) Enumeration type

Object Pascal does not support each enumerated element to specify a value.

For example, C / C can be defined: Enum aweek {sun = 1, mon, tue ...};

Only Object Pascal can only be defined: aweek = (Sun, MON, TUE ...);

(4) array

C / C does not support the array of subscripts specified in Object Pascal, and the subscript can only start from 0.

(5) structure

Object Pascal does not support bitfield in Struct (called Record in Pascal). Bitfield

You can store structural members in Bit (do not need whole bytes) to reduce the storage space of the structure. Not access

Efficiency will decrease.

(6) String

String processing is one of the strengths of Object Pascal. Flexible and efficient string processing can be supported. Strictly speaking,

C / C cannot support native string types. Char * and char [] are more similar to user-defined types because

The compiler does not support the memory automatic allocation and recycling of strings, requiring users to call Malloc () and Free ().

Object Pascal also supports a C / C style string (called PCHAR). However, the String type is more powerful. From

In implementation, Object Pascal's string type uses a prefix represents the string length (1 byte prefix Short

String and 4-byte prefix Long String, two String are automatically compatible, and long string is also compatible

PCHAR), CHAR * and CHAR [] in C / C uses a suffix chr (0) to indicate the end of the string. Different representations

Handling performance has a big impact: for a large number of complex string operations, you can write more than Object Pascal

C / C fast dozens of programs (many PASCAL compilers written in Pascal, such as Free Pascal,

Pascal Pro, etc., although the technical level is general, but the compilation speed is also very fast, and it is also benefited from Pascal to some extent.

String processing efficiency). For example, take a string length function Length / strlen (), Object Pascal implementation only

To a MOV directive, and the implementation of C / C needs to perform a repeating string scan until the end is found.

Object Pascal's String type also has an advantage in supporting Unicode characters. To know the string of C / C

It has brought a lot of trouble to the modern operating system to support Unicode characters, such as the serial "ABC 'Unicode is represented as:

41 00 42 00 4300, which makes the C / C program at all from the string at all. Although the modification compiler can be very

It is easy to solve this problem, but the optical modification compiler is not enough, but also modify the operating system, otherwise the previous large number of C / C programs cannot be used on the new operating system (this is a disaster - you have no Notepad. ,how

do? :-). Windows provides two sets of solutions using any API involving string processing. For example, Textout,

TEXTOUTA for processing ASCII characters and Textoutw for processing Unicode characters. Unix / linux

Another way: Any API involving string processing uses UTF8 compression coding (a code similar to RTF)

METHODS: All ASCII characters are stored directly, multi-byte characters are used to escape), although (reluctant) guarantees

The capacity is not small at cost.

(String / Ansistring in PS: C is the simulation of class, so performance ...)

(7) Multiple inheritance

There is no doubt that Object Pascal does not support multiple inheritance; and it can also see the meaning of Borland to increase this feature.

(In fact, it is easy to increase). Object Pascal implements multiple inheritances through the interface (Interface).

Interface can not only introduce objects implemented with Object Pascal, but also in other languages.

COM / DCOM / CORBA object. Do you really need multiple inherits? I think most of the programmers have never been like me.

Using multiple inheritance (such a powerful and flexible architecture of VCL is not used at all, multiple inherits).

(PS: Java and Delphi do not support multiple inheritance, but also using Interface to achieve multiple inheritance. In fact, this is also

Not surprising: JDK 1.2 and Java 2 are mainly developed by Borland, and Sun is only named. Don't believe you, see Java classes

The library is not very like VCL. :-)

(8) Object template

Object Pascal does not support object templates. Because the object template is just a macro language (the macro itself is not

C / C language characteristics).

(9) Overload

The Object Pascal supports the overload of the function / process and does not support operator overload. C all support.

(PS: I personally prefer Object Pascal to increase support for operator overload)

(10) Bit and logical operations

Object Pascal and C / C have no difference in this regard.

C / C &, |, ~, ^, >>, <<, &&, ||,! Other than Object Pascal and, OR, NOT, XOR,

SHR, SHL (AND, OR, NOT, XOR) is used for bit operations and logical operations). However, C / C does not support logic

XOR (a xor b = a and not b or not a and b, or can be implemented).

(11) style

In fact, this is an important reason I prefer to use Delphi (I often use C because of the reasons for work.

compilation). Just like some articles said: "Object Pascal and C are the same heavyweight language", it is really difficult

Differentiate, the difference is mainly in style. C emphasizes flexible, and Object Pascal is more implicit and beautiful.

The author of the "programming language: design and implementation" also praised Pascal "a very beautiful language." Have

People therefore think of Pascal "clumsy". In fact, it should be "Avenue to Jane". I think it is also written using C .

It is a good job, don't sell skills. Only programmers with low levels like selling skills (the level is too low, it can't be found, too high and I don't want to sell it). I am like someone to comment on the "plain" of Li Changyi, but Ma Xiaochun again

How to "ghost" can only be willing to worship.

It is actually C vs Object Pascal. But it also applies to VC VS Delphi.

(PS: VC does not realize the characteristics of all ANSI / ISO C 95 specifications (currently the latest standards) (So some people

Today is C ). And C Builder is fully compatible with ANSI / ISO C 95 specification and supports AT & T (C "birth.

The entire C extension characteristics of UNIX V. Some people call "M $ adhere to industrial standards, Borland will be modified", this

Is wrong. Delphi is also fully compatible with ANSI / ISO Pascal 1983/92 specification, as well as Apple Object Pascal

(Use Code Warrior Professional should know Apple Object Pascal).

)

3. Function and other

(1) Obtainability

There is no doubt that Delphi has a huge advantage, this doesn't have to say more.

(PS: The truly great greatness of Delphi is not due to ease of use, and you need complexity.

Hygically, you need flexibility to flexibility; write programs without visualization (visualization is just Object Pascal

On the other side of the object structure, write programs without VCL)

(2) Scope of application

VC can make any hardware allowed work. Delphi can also.

("No !!!", I know that you will say this, you will mention vxd. :-)

Delphi can't write VXD (in fact, if you generate OBJ with Delphi, use the LINK connection to M $, it is possible)

Because (have you seen non-M $ tools to generate vxd? Watcom? Symantec? Gnu? ...), but not technology

The reason. VXD's Le (Linear Executable) file format first appears in Windows 3.0, format

Simple (simple than NE and PE format), basically a memory image file. But M $ don't know what motivation is

Other company's software is not allowed to generate its (patent) format.

Delphi is a SYS and a new WDM (Windows Driver Model) driver that can be written in Windows NT, these

Use ordinary DLL format.

(PS: From the legal perspective, you write a program yourself, not only the MS Word file is not allowed to generate the MS Word file)

(PS: Have a "Miracle Age" (Age of Wonders, HTTP: //www.epicages.com)?

Delphi 3 written. Both pictures and speeds are better than the "Evil Times" of M $. But I don't like to play the strategy game, I

Like the duke3d and quake series, there is Tomb Raider Series. :-)

(3) Integrated development environment

Delphi's IDE is more concise / easy to use.

(4) Database support

In this regard, in this regard, in addition to Delphi's brothers C Builder / JBuilder I am afraid only Power Builder (barely)

Delphi compared to Delphi. However, the performance and scope of use of PB are too far (not how to call POOR Builder? :-).

(PS: My Impression is that most of the network-based / large database C / S and multi-layer structures are used.

Delphi / jbuilder development)

(5) Network function

Delphi also has a certain advantage. Especially in the development of Internet. (6) Component support

In addition to Object Pascal-based VCL / CLX, Delphi also supports COM / DCOM-based components (such as ActiveX).

Plus CORBA support. VC only supports components based on COM / DCOM.

(7) Application framework / design ideas

VCL is at least one generation than MFC, which is not much. The amount of MFC is alone but is OWL (a less successful) model.

Imitation, it is not as good as OWL from design ideas. As a basic class library (regardless of visual or not),

At the moment, we should focus on the simple and effective, maintain certain elasticity and abstraction (abstract means starting with function,

For example, Tcanvas in the VCL is an excellent abstraction to DC (Device Context) in Windows, compared to MFC

The design is high in the design. Not, there is an face, move the API (unfortunate, M $ program)

The staff have been doing this job for many years. Take a look at some of the MFC, it's too horrible: usually

The parameters such as HWND and DC (already saved as a private data), the method is simply

Turn on the Windows API. What is the meaning of this? Will the Windows API are you? For example,

It is better to call CreateThread / ExitThread / ResumeThread / in the MFC.

The API and the API such as SetThreadPriority are more convenient and fast.

(PS: Have you used Delphix (http://www.yks.ne.jp/~ Hori/)? DirectX is so complicated to use

The Object Pascal package is so good again to prove the powerful VCL architecture.

(8) debugging

The two are different. VC source debugging more user friendly, while Delphi / C Builder is multithreaded

The debugging support is better.

(PS: It is more than a separate debugging tool, Borland's Turbo Debugger is much better than the codeview of M $)

(9) Run environment / system requirements

It should be said to be almost. The startup speed of VC is indeed faster than Delphi (this is mainly relative to Delphi 4 .

The startup of Delphi 3 is still very fast). This is largely due to a fact: VC is mainly a text based on text.

The traditional development environment of this editor. Code Warrior Professional is not a faster startup?

As for the "a database program to bring 3 ~ 5MB BDE Run File", this may be due to installation

"All BDE Installation" (default) instead of "partial BDE is used in INSTALLSHEILD, WISE.

"If you only use the desktop databases such as Access, DBASE, FoxPro, Paradox, only a few hundred

K 's running files. Database programs developed with M $ tools also bring a lot of ODBC, DAO, JET,

ADO, MSDE is running files. In Delphi 5, if you use AdoExpress, InterBase Express

If you access the database, you may not take BDE.

(PS: No matter what to say, Borland has to work hard in the start of Delphi / C Builder!)

(10) Product quality / stability

There is article "VC quality, high stability". Is it really? Visual Studio's Service Pack

Not all going to 4? What is a service pack? Is it mainly bug fix patch? ! Borland

The tool is not perfect, and the "memory vulnerability" does exist in the VCL of Delphi 3, which will lead to programs developed with D3.

Sometimes (not always) cannot release the allocated memory after exiting. VC has a lot of problems: IE is written with VC ,

Start a few times when you are online, open the customs, and finally turn off, see how much your system resources are left? Also often guide

To "General Protection Error". Ultra edit is written with VC , and the same problem. its

In fact, the quality is not good, and the operation is stable and unstable, depending on the development of the developer's level / responsibility. ratio

If the Tomb Raider Series and Quake Series games are developed with VC , but the picture quality and operation are obviously

The Quake series is more winning. As Aeronautics and Aerospace (NASA), Russia NAS (RSA), Bank of America (Bank

Of America, more than $ 500 billion in big banks), else, such as American Airlines, AT & T,

Large agencies / companies such as BMW, Compaq, BBC Television, British Telecom are developed with Delphi

Complex, enterprise-level (comic, some people actually call "develop enterprise desktop applications with VC", do not know

Level applications and desktop applications are relatively) applications (at http://community.borland.com

(Borland Community Site) There is a product introduction developed by Delphi and C Builder, if someone else wants

Said "... stability and reliable is the hard truth, I have to endure love," that he is afraid to have a homemade development tool.

转载请注明原文地址:https://www.9cbs.com/read-6025.html

New Post(0)