首页 \ 问答 \ 编译器优化以减少可执行代码的字节数(Compiler optimization to reduce bytes of executable code)

编译器优化以减少可执行代码的字节数(Compiler optimization to reduce bytes of executable code)

编译器(例如javac)是否有可能在编译之前扫描整个项目中未使用的方法和变量 ,然后在没有那些未使用的方法和变量的情况下编译项目,以便最终减少可执行代码的字节数。

如果这是一个编译器优化,我会创建一个包含所有帮助器方法的大型库,并将其导入我的所有项目中,而不用担心它如此巨大会影响我的软件大小。

我理解这可能是不可能的,如果你没有你正在使用的那些库的源代码(导入),但我说的是你有源代码的情况

是否有一个类似的工具/ IDE插件? 我认为这也可以在编译之前一步完成。


Is it possible for a Compiler (for ex. javac) to scan your whole project for unused methods and variables before compilation and then compiles the project without those unused methods and variables such that you end up with fewer bytes of executable code.

If this would be a compiler optimization, I would create one huge library that contains all my helper methods and import it in all my projects and not worry that it being so huge could effect my Software size.

I understand this could be impossible, if you do not have the source code of those libraries you are using(importing), but I am speaking of the case where you have the source code.

Is there a tool/IDE plugin that does something similar? I would think this could be also done in one step ahead of the compilation.


原文:https://stackoverflow.com/questions/18028956
更新时间:2023-07-11 22:07

最满意答案

首先,对象实例的大小本身并不重要。 该类应设计为具有单一责任,如果需要540字节的数据,那么就是这样。

但是,540字节是一个非常大的数字。 这是135个整数或指针。 这就像22 std::vector s。 我很难想象单个责任区域可能需要这么多物体。 但同样,尺寸本身不是问题。 问题是如果你的班级负责的比他们应该做的更多。

我在想,既然不是所有的窗口都有子节点,我可能会将处理子节点的代码(它的对齐等)拆分成一个单独的类并指向它。 文本,图标和滚动等也是如此。

听起来你基本上只有一个EverythingUI类。 是的,这是糟糕的设计。 由于这个原因拆分它。 处理文本与处理图标或滚动或无关......将它们放在不同的类中。


First, the size of an object instance in itself doesn't really matter. The class should be designed to have a single responsibility, and if that requires 540 bytes of data, then so be it.

However, 540 bytes is a unusually big number. It's 135 integers or pointers. It's something like 22 std::vectors. I have a hard time imagining that so many objects can be required for a single area of responsibility. But again, the size itself isn't the problem. The problem is if your class is responsible for more than it should.

I was thinking, that since not all windows have children, I might split parts of the code that handles having children (its alignment etc) into a separate class and have a pointer to it. Same goes with texts, icons, and scrolling etc.

It sounds like you've basically got a single EverythingUI class. And yes, that is bad design. Split it up for that reason. Handling of text has nothing to do with handing of icons or scrolling or... Put them in different classes.

相关问答

更多

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。