不知道大家有没有看这篇贴子:
http://expert.csdn.net/Expert/topic/2041/2041804.xml?temp=.7627069
该源码经编译后,当我看到生成的可执行文件时,吓了一跳,居然有942k,再看看vs.net2003用C#写的类似的一个小程序,不过才40K,居然差这么多,心想delphi.net的编译器不至于这么差吧,一定有什么其他的原因。
    后来检查了一下代码,原来是这些东西在做怪:
         Borland.Win32.Windows,
         Borland.Win32.Messages,
         Borland.Delphi.SysUtils,
         Borland.Delphi.Variants,
         Borland.Delphi.Classes,
         Borland.Vcl.Graphics,
         Borland.Vcl.Controls,
         Borland.Vcl.Forms,
         Borland.Vcl.Dialogs,
         Borland.Vcl.Menus,
         Borland.Vcl.StdCtrls,
         Borland.Vcl.ComCtrls;
   原来宝兰公司的这些类库是很占空间的,而vs中则是使用了原生的.net framework,所以VS生成的可执行文件比Delphi.net生成的可执行文件小得多,下面是我利用原生的.net framework写的代码以及用vs.net C#写的代码,他们都将生成一个不包含任何组件的空白窗体:DELPHI.NET代码:program DelphiDotNetTest;uses
  System.Windows.Forms;var
  Form1: System.Windows.Forms.Form;begin
  Form1 := System.Windows.Forms.Form.Create;
  Application.Run(Form1);
end.
vs.net C#代码:using System;
using System.Windows.Forms;namespace WindowsApplication2
{
class class1
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main() 
{
Application.Run(new System.Windows.Forms.Form());
}
}
}
结果将两个编译好的可执行文件相比较,DELPHI.NET 生成的文件只有4.5K,而VS生成的代码却有20K,看来Delphi for .net的编辑器还是相当不错的。如果你有兴趣,可以用微软件的中间语言查看器来对比一下Delphi.net与VS生成的.net汇编代码有什么区别。欢迎和我讨论:[email protected]

解决方案 »

  1.   

    》》》》结果将两个编译好的可执行文件相比较,DELPHI.NET 生成的文件只有4.5K,而VS生成的代码却有20K,看来Delphi for .net的编辑器还是相当不错的这种比较是很没什么用的,
    想想看微软知道这个但为什么还要那20K,他为什么不直接用汇编可能1K都用不着。
    大部分的地方可能是放一些全局变量。
    还有异常处理之类的东西在里面。比较这个,没用!!!
    要比较的话,拿一个算法来比较他们的优化程序才是真的。虽然C#我不熟但是以前的C++中的MAIN原代码我稍微看了一些的。
      

  2.   

    sevencat(七猫):
        如果你有兴趣,可以用微软件的中间语言查看器来对比一下Delphi.net与VS生成的.net汇编代码有什么区别
      

  3.   

    delphi.net没有,
    C#也没装我的只装了VC++
    原代码在光盘里面能找到,
    最初我看的汇编,
    大致是
    先取得操作系统版本号(可能还有一个DOS下面的头)
    取得命令行参数...
    导入一系列函数。
    try...
    main()
    catch()...)
    应该还有一部分是全局变量,
    比如说什么出错了之类的要有个全局的error变量。有空我再详细的看一下,
    不过这样比是不公平的。
    这样比的话肯定是汇编最好了。
      

  4.   

    下面分别是delphi.net和C#生成的可执行文件通过反编译得到的类信息delphi.net:.assembly extern mscorlib
    {
      .publickey = (00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 ) 
      .ver 1:0:5000:0
    }
    .assembly extern System.Windows.Forms
    {
      .publickey = (00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 ) 
      .ver 1:0:5000:0
    }
    .assembly DelphiDotNetTest
    {
      // --- The following custom attribute is added automatically, do not uncomment -------
      //  .custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(bool,
      //                                                                                bool) = ( 01 00 00 01 00 00 ) 
      .hash algorithm 0x00008004
      .ver 0:0:0:0
    }
    .mresource public _ResourceStrings.resources
    {
    }
    .module DelphiDotNetTest.exe
    // MVID: {63AEBC5B-FCE5-4F15-910A-5BD97E0D59DC}
    .imagebase 0x00400000
    .subsystem 0x00000002
    .file alignment 512
    .corflags 0x00000001
    // Image base: 0x03030000
    vs.net C#.assembly extern mscorlib
    {
      .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )                         // .z\V.4..
      .ver 1:0:5000:0
    }
    .assembly extern System.Windows.Forms
    {
      .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )                         // .z\V.4..
      .ver 1:0:5000:0
    }
    .assembly WindowsApplication2
    {
      .custom instance void [mscorlib]System.Reflection.AssemblyCopyrightAttribute::.ctor(string) = ( 01 00 00 00 00 ) 
      .custom instance void [mscorlib]System.Reflection.AssemblyKeyFileAttribute::.ctor(string) = ( 01 00 00 00 00 ) 
      .custom instance void [mscorlib]System.Reflection.AssemblyDelaySignAttribute::.ctor(bool) = ( 01 00 00 00 00 ) 
      .custom instance void [mscorlib]System.Reflection.AssemblyTradeAttribute::.ctor(string) = ( 01 00 00 00 00 ) 
      .custom instance void [mscorlib]System.Reflection.AssemblyKeyNameAttribute::.ctor(string) = ( 01 00 00 00 00 ) 
      .custom instance void [mscorlib]System.Reflection.AssemblyProductAttribute::.ctor(string) = ( 01 00 00 00 00 ) 
      .custom instance void [mscorlib]System.Reflection.AssemblyCompanyAttribute::.ctor(string) = ( 01 00 00 00 00 ) 
      .custom instance void [mscorlib]System.Reflection.AssemblyConfigurationAttribute::.ctor(string) = ( 01 00 00 00 00 ) 
      .custom instance void [mscorlib]System.Reflection.AssemblyDescriptionAttribute::.ctor(string) = ( 01 00 00 00 00 ) 
      .custom instance void [mscorlib]System.Reflection.AssemblyTitleAttribute::.ctor(string) = ( 01 00 00 00 00 ) 
      // --- The following custom attribute is added automatically, do not uncomment -------
      //  .custom instance void [mscorlib]System.Diagnostics.DebuggableAttribute::.ctor(bool,
      //                                                                                bool) = ( 01 00 01 01 00 00 ) 
      .hash algorithm 0x00008004
      .ver 1:0:1294:38123
    }
    .mresource public WindowsApplication2.class1.resources
    {
    }
    .module WindowsApplication2.exe
    // MVID: {8076B33D-BD6E-40DC-A1A8-4C045EAAF4D4}
    .imagebase 0x00400000
    .subsystem 0x00000002
    .file alignment 4096
    .corflags 0x00000001
    // Image base: 0x03030000与DELPHI.NET不一样的是,在C#中声明了一些变量?对像?,不知道这些代码是做什么用的?
      

  5.   

    以后的D8,完整版就会有IDE开发环境了,不用那么麻烦的