使用高级语言有什么缺点?

What are the disadvantages of using high-level languages?

我认为明显的优点是可维护性、对程序员友好等,但缺点是什么?

编译器是否需要额外工作以在可能不需要的地方进行转换?

是否存在由于上述缺点而使低级语言更适合某项任务的情况?

不自己分配内存是一回事。这些语言背后的程序员创建了垃圾收集器,它们有时(大部分)会为您提供大量内存。

以JavaScript为例。如果你这样做 var arr = array(501); 它可能会给你 600 字节,或 1000 甚至更多。

对于低级程序,如嵌入式设备上的操作系统或视频游戏(PS4 上的游戏等),内存至关重要。所以你不能承受比你需要的更多 space。

简而言之:由于非常具体的优化,低级语言可以产生更好的性能。

低级语言的优点:

  • 您可以专门针对和利用芯片功能(或寄存器)
  • 通常情况下,如果您知道自己在做什么,它会(很多)更快,但这种情况很少见。

高级语言的缺点:

  • 您需要某种编译器才能将 HLL 转换为 LLL
  • 在某些情况下(例如 Java / C#),你有一个解释器,两者之间也消耗资源(但也可以在 运行 程序时优化自身!)

这里是 LLL 优势的更详细列表:

  • you can access machine-dependent registers and I/O
  • you can control the exact code behavior in critical sections that might otherwise involve deadlock between multiple software threads or hardware devices
  • you can break the conventions of your usual compiler, which might allow some optimizations (like temporarily breaking rules about
    memory allocation, threading, calling conventions, etc)
  • you can build interfaces between code fragments using incompatible conventions (e.g. produced by different compilers, or separated by a
    low-level interface)
  • you can get access to unusual programming modes of your processor (e.g. 16 bit mode to interface startup, firmware, or legacy code on
    Intel PCs)
  • you can produce reasonably fast code for tight loops to cope with a bad non-optimizing compiler (but then, there are free optimizing
    compilers available!)
  • you can produce hand-optimized code perfectly tuned for your particular hardware setup, though not to someone else's
  • you can write some code for your new language's optimizing compiler (that is something what very few ones will ever do, and even they not often)
  • i.e. you can be in complete control of your code

来源:http://www.tldp.org/HOWTO/Assembly-HOWTO/x133.html