java 抽象方法 虚方法的区别_声明抽象类(纯虚方法)会大幅增加二进制大小
以下是故事:我正在使用AC6 Toolpack為Linux中的ARM Cortex-M0處理器開發C軟件 . 在我使用Keil(在windows中)(擁有自己的工具鏈)之前,我已經遷移到GNU-toolchain((GNU Tools for ARM Embedded Processors)5.2.1) . 我意識到的第一件事是;二進制文件大小大幅增加 . I have tested every compiler optimizations (except link time optimization, it gives an error in inline assembly, not part of question but may be related to answer). 然后開始用任何可用的工具檢查可執行文件(elf文件不是bin,gnu生成兩者):objdump,readelf,nm . 我發現了一些導致尺寸增加的符號,重要的是:' d_print_comp_inner ' , ' d_exprlist ', ' d_template_args ' . 但不知道是什么導致這些函數出現在二進制文件中 . (我使用過最小的庫:nano newlib) . 長話短說我開始逐一消除代碼以找到罪魁禍首 . 最后是抽象方法聲明!
將功能定義為
virtual Return_type function_name(...)=0;
代替
virtual Return_type function_name(...);
添加45 KB和我提到的符號 . And this is the only change in source code. Empty definition in base class is present. Note that: method is still virtual and overridden in child classes
沒有抽象類的大小輸出:
text data bss dec hex filename
15316 24 4764 20104 4e88 temc_discovery.elf
抽象類的大小輸出:
text data bss dec hex filename
61484 128 4796 66408 10368 temc_discovery.elf
這里的方法是抽象的符號和他們的大小,消除了兩個版本中出現的符號和他們的大小 . (使用 nm 工具 . 不完整列表,大小> = 0x60的列表)
00002de4 t d_print_comp_inner
00001a34 t d_exprlist
00000ca4 t d_template_args
00000678 t d_type
00000574 t d_print_mod
000003f8 t d_encoding
000003e0 r cplus_demangle_operators
000003c8 t d_expression_1
000003a8 t d_name
00000354 t d_demangle_callback.constprop.15
000002e0 t d_print_mod_list
00000294 r cplus_demangle_builtin_types
00000268 t d_unqualified_name
00000244 T _printf_i
00000238 t d_print_function_type.isra.11
000001fc T _svfprintf_r
000001fc T _svfiprintf_r
000001f4 t d_print_array_type.isra.10
000001ce t d_print_cast.isra.12
0000018c t d_substitution
00000110 t d_operator_name
0000010c T __sflush_r
000000e8 T __swsetup_r
000000e6 t d_cv_qualifiers
000000e0 t d_print_subexpr
000000e0 t d_expr_primary
000000dc T _printf_common
000000cc T __cxa_demangle
000000c8 t d_source_name
000000c4 r standard_subs
000000c4 T __ssputs_r
000000b0 T __swbuf_r
000000ac T _malloc_r
000000a8 T _fputs_r
000000a4 T __smakebuf_r
000000a0 T __gnu_cxx::__verbose_terminate_handler()
00000096 t d_print_expr_op
0000008c T _free_r
0000008c t d_parmlist
0000008a t d_growable_string_callback_adapter
0000007c T __sfp
00000072 t d_append_buffer
00000068 T __sinit
00000060 d impure_data
我所熟悉的一些名稱(例如printf,flush,malloc,fputs等)在源代碼中甚至沒有提到 .
任何人都知道造成這種行為的原因是什么?
Update: 我已經使用標志 --noexception 禁用異常,所以我沒有給出任何異常 . 事實證明,這與答案有關,這里提到這一點很好 .
總結
以上是生活随笔為你收集整理的java 抽象方法 虚方法的区别_声明抽象类(纯虚方法)会大幅增加二进制大小的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 一棵树多少钱啊?
- 下一篇: java 无法取消引用_Java的新手,