编译器优化以减少可执行代码的字节数(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
最满意答案
首先,对象实例的大小本身并不重要。 该类应设计为具有单一责任,如果需要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::vector
s. 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.
相关问答
更多-
TCP/IP模型是一个________。[2023-05-19]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
Maven 3 - 值得吗?(Maven 3 - Worth it? [closed])[2023-10-17]
Maven 3的新功能 这里有一些你可以在网上找到的一些汇编。 向后兼容性 --Maven 3是向后兼容的,这是非常重要的(特别是对于那些经历了Maven 1到Maven 2转换)。 无版本的父元素--Maven 3将删除在子模块中指定父版本的需要。 这是伟大的(在Maven 3.1)。 Mixins - 用于POM组合(在Maven 3.1 AFAIK中)。 使用属性的XML POM格式 - 您可以使用属性而不是元素。 Polyglot Maven - 您可以使用不同的语言编写您的POM文件(我个人对XM ... -
别; 除非您频繁移动内存 如果你正确地做到这一点并不麻烦: std::vector
::const_iterator _lastPosition(gameInfoV.begin()); // ... for (std::vector ::iterator info=_lastPosition; it!=_gameInfoV.end(); ++info) { if (!info->bhasbeenAdded) { if (DoWeNeedNo ... -
在网络字节顺序中加倍时,为什么要用4字节块完成?(When putting a double in network byte order, why is it done in 4 byte chunks?)[2022-06-21]
将IEEE 754双精度转换为网络字节顺序的正确方法是什么? 据我所知,IEEE754双打没有标准的网络字节顺序。 显然人们已经推出了他们自己的序列化。 “网络字节顺序”最初是在Internet协议的上下文中出现的,其中通常发送32位值(IPv4地址)和16位值(例如端口号)。 RFC 1700最初定义了该术语,但该RFC现已废弃 ,无需替换。 对于double或任何其他数据的通信,两端应同意并遵循协议规范 。 这将说明双重编码的方式。 您链接到的帖子,可能遵循一个协议,该协议指定将IEEE754 64位格 ... -
是否值得将540字节的类减少为更小的块?(Is it worth cutting down a 540 byte class into smaller chunks? (C++) [closed])[2021-11-13]
首先,对象实例的大小本身并不重要。 该类应设计为具有单一责任,如果需要540字节的数据,那么就是这样。 但是,540字节是一个非常大的数字。 这是135个整数或指针。 这就像22 std::vector s。 我很难想象单个责任区域可能需要这么多物体。 但同样,尺寸本身不是问题。 问题是如果你的班级负责的比他们应该做的更多。 我在想,既然不是所有的窗口都有子节点,我可能会将处理子节点的代码(它的对齐等)拆分成一个单独的类并指向它。 文本,图标和滚动等也是如此。 听起来你基本上只有一个EverythingUI ... -
首先,可能需要熟悉您的流密码。 Blowfish使用64 位的块大小加密/解密; 不是字节。 只要你理解你所指的64个“字节”是你的要求而不是Blowfishes,并且Blowfish只需要8个字节的块。 也就是说,循环遍历文件的大小是算法块大小的倍数,一次提取一个64字节帧的解密数据肯定是可行的。 #include
#include #include #include int main(int a ... -
这是我将如何做到这一点: var size = 4; var messages = Encoding.UTF8.GetBytes("HelloWorld") //48 65 6C 6C 6F 57 6F 72 6C 64 .Select((b, i) => new { b, i }) // Enumerable of byte and index .GroupBy(x => x.i / size, x => x.b) // group by index divide ...
-
您可以使用FileStream读取二进制文件,然后对其进行处理。 这里有一个例子: using (var inFileSteam = new FileStream(@"C:\path\to\file.bin", FileMode.Open)) { byte[] buffer = new byte[5 * 1024 * 1024]; // 5MB in bytes is 5 * 2^20 int bytesRead = inFileSteam.Read(buffer, 0, buffer.Le ...
-
法尔汉, 在ChunkedImageActivity.java中,使用Collections.shuffle(imageChunks); 在ArrayList之后imageChunks = getIntent()。getParcelableArrayListExtra(“image chunks”); 你会得到洗牌的图像。 要将这些图像存储在SD卡中,请使用FileOutputStream。 点击此链接http://looksok.wordpress.com/2013/07/13/android-tutor ...