如何编写一个小程序?

Ben*_*iss 0 delphi filesize

我想编制高效的程序并保持我的FileSize非常小.但是,我想知道一些提示如何实现这一目标.

例如,对于小型FileSize更好的是:

或者:

if .... = '1' then begin
 ...
end;
Run Code Online (Sandbox Code Playgroud)

要么:

if ..... = inttostr(1) then begin
...
end;
Run Code Online (Sandbox Code Playgroud)

要么:

if .... = inttostr($0001) then begin
...
end;
Run Code Online (Sandbox Code Playgroud)

要么:

case of intvar
  1: ...
  2: ...
end;
Run Code Online (Sandbox Code Playgroud)

然后我尝试了一些东西,我很惊讶.我在我的项目中创建了另一个单元,它将Strings存储为常量,然后我使用常量变量来替换项目中的字符串.出于某种原因,这会引发我的FileSize,尽管我现在将双重使用的字符串替换为var.

将内容存储在变量中比将它们直接放入代码更好吗?!例如:

Function1(param1, param2, param3); // this code is used about 20 times in my project
Run Code Online (Sandbox Code Playgroud)

或者我是否更好:

Avar = Function1 (param1,param2,param3); // Store this once in a var and then replace it
Run Code Online (Sandbox Code Playgroud)

那怎么样:

if ... = TRUE 
Run Code Online (Sandbox Code Playgroud)

要么:

if ....
Run Code Online (Sandbox Code Playgroud)

与...一样:

if .... = FALSE
Run Code Online (Sandbox Code Playgroud)

要么:

if not(...)...
Run Code Online (Sandbox Code Playgroud)

有关为较小的FileSize进行高效编程的其他任何提示吗?

提前致谢.

我用的是Delphi7

Fra*_*ois 11

我很抱歉直言不讳,但是你把车推到马前.

如果您真的想知道如何在不知道给定示例中代码变体会产生什么差异的情况下缩小可执行文件的大小,那么您应该立即停下来阅读/学习/练习,直到您对语言和编译器有更多了解为止. .

那么你就会明白你的问题本身没什么意义,因为你已经可以通过你得到的所有相关评论看到.

  • 完全相同的源代码可能导致完全不同的可执行文件和不同的源代码可能导致相同的可执行文件,具体取决于编译器选项/优化
  • 如果您的主要目标是微管理/控制生成的exe,则直接在汇编程序中编程.
  • 如果您想知道编译器生成的内容,请了解如何使用CPU视图.
  • 程序首先是正确性,然后是可读性/可维护性
  • 只有这样,如果需要(暗示使用正确的指标/工具),您可以优化速度,内存使用或文件大小(可能是最不实用/需要的)