How much footprint does C++ exception handling add

后端 未结 8 1237
有刺的猬
有刺的猬 2020-11-28 05:50

This issue is important especially for embedded development. Exception handling adds some footprint to generated binary output. On the other hand, without exceptions the err

8条回答
  •  囚心锁ツ
    2020-11-28 05:59

    One thing to consider: If you're working in an embedded environment, you want to get the application as small as possible. The Microsoft C Runtime adds quite a bit of overhead to programs. By removing the C runtime as a requirement, I was able to get a simple program to be a 2KB exe file instead of a 70-something kilobyte file, and that's with all the optimizations for size turned on.

    C++ exception handling requires compiler support, which is provided by the C runtime. The specifics are shrouded in mystery and are not documented at all. By avoiding C++ exceptions I could cut out the entire C runtime library.

    You might argue to just dynamically link, but in my case that wasn't practical.

    Another concern is that C++ exceptions need limited RTTI (runtime type information) at least on MSVC, which means that the type names of your exceptions are stored in the executable. Space-wise, it's not an issue, but it just 'feels' cleaner to me to not have this information in the file.

提交回复
热议问题