是否有“函数大小分析器”? .NET 在那里?

发布于 2024-10-31 05:28:27 字数 376 浏览 1 评论 0原文

我正在开发一个小型框架,其中包含各种实用程序 - 越小越好,这样它就不会导致使用它的可下载程序的大小膨胀。有没有任何工具可以显示我的方法、接口和类的大小(以字节为单位)?

(我一直在删除各种类来查看文件大小变化了多少,但由于某种原因,DLL 始终是 4 KB 的倍数,因此我无法准确判断给定类有多大,更不用说方法了。无论如何,这种方法很痛苦,因为当我删除一块时,我还必须删除依赖于它的任何代码。)

我之前问过这个问题 对于 C++(结论是:不,但在 Linux 中有一个有用的 shell 命令)。

I'm developing a small framework filled with various utilities--the smaller the better, so that it doesn't bloat the size of downloadable programs that use it. Is there any tool to reveal the size in bytes of my methods, interfaces and classes?

(I've been removing various classes to see how much the file size changes, but for some reason the DLL is always a multiple of 4 KB so I can't tell precisely how big a given class is, let alone a method. Anyway, that approach is a pain in the ass because when I remove one piece, I have to also remove any bits of code that depend on it.)

I asked this question earlier for C++ (conclusion was: no, but in Linux there's a useful shell command).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

爱给你人给你 2024-11-07 05:28:27

当您编辑内容时文件大小不会改变的原因是 PE 格式的每个部分都与特定边界对齐。 (例如,.text 部分通常从偏移量 0x1000 开始),其他部分根据其内容的大小进行对齐。它们之间填充了“\0”,因此当安装程序压缩文件时,将有效消除空间。

值得怀疑的是,您是否需要担心方法的大小,因为它们通常是数十字节的量级。每个方法的元数据占用的空间都比这个多。与重写方法相比,通过缩短变量名称和字符串文字可以节省更多空间。

The reason the file doesn't change size when you edit things is because each section of the PE format is aligned to certain boundaries. (Eg, the .text section will usually begin at offset 0x1000), and the other sections are aligned, depending on the size of their content. Between them is padding of '\0', so that space will effectively be eliminated when the file is compressed by an installer.

It's doubtful that you need to worry about the size of your methods, as they will usually be in the magnitude of tens of bytes. The metadata for each method takes up more space than that. You'd save more space by shortening variable names and string literals than you would rewriting methods.

把时间冻结 2024-11-07 05:28:27

尝试反思。 MethodInfo 类中有一个方法可以获取 MSIL 表示形式:
http://msdn.microsoft.com/en-us /library/system.reflection.methodbase.getmethodbody.aspx

Try reflection. There is a method in MethodInfo class to get the MSIL representation:
http://msdn.microsoft.com/en-us/library/system.reflection.methodbase.getmethodbody.aspx

两人的回忆 2024-11-07 05:28:27

.NET Reflector 显示该信息(反编译为 MSIL 时,每条指令都显示一个“行号”,即距方法开头的偏移量(以字节为单位))

.NET Reflector shows that information (when decompiling to MSIL, each instruction is shown with a "line number" that is the offset, in bytes, from the beginning of the method)

蒲公英的约定 2024-11-07 05:28:27

Windows

ildasm

Mono

monodis

将通过命令行反汇编程序集(或其中的一部分)

Windows

ildasm

Mono

monodis

Will disassemble the assemblies (or parts of them) via the commandline

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文