由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 有大侠讲讲RTTI和exception的问题么?
相关主题
几个问题菜鸟请教smart pointer
请问C++ exception后如何清理function stack上的内存资源?一道编程题 - throw Exceptions
C++ 的 exception handlingTwo questions about handling exceptions in C++
C++: exception: out-of-order execution?一个Quant Developer的C++面试题
问一个constructor的问题 (转载)new一定要和delete配对吗?
请教一下,exception时,destructor一定会被调用么?请教显示object name的问题(c++)
请教个Bloomberg 的 C++ 题目包含指针的类和vector的问题
一个c++ constructor的问题, thanksWhat is wrong with the constructor calling?
相关话题的讨论汇总
话题: exception话题: rtti话题: when话题: thrown
进入Programming版参与讨论
1 (共1页)
f*******y
发帖数: 988
1
为啥不建议使用呢?主要问题在哪里?
X****r
发帖数: 3557
2
谁不建议使用就问谁啊。
如果你这个是对于早先有人贴的Google Style Guide所问的,
你看了上面每条规定所对应的详细解释吗?
Google的理由并不是对所有人都成立的。
z******i
发帖数: 59
3
Performance problem.
RTTI: dynamic cast is expensive
exception: extra codes are generated for stack unwinding. Even if they are
not used, extra code size means:
1. Load code from main memory to instruction cache. cache pollution.
2. CPU is pipe-lined, CPU still needs to decode the assembly codes.
3. In order to preserve stack, compiler might not be able to optimize the
local variables to register. Big performance hit.
r*********r
发帖数: 3195
4
太复杂,属于让你 shoot your own foot 部分,禁了比较好,
程序出错少。尤其对于古狗那些比较傻的。
r*********r
发帖数: 3195
5
i think exception has a more damaging problem.
that is, it will cause memory leak, when the exceptional path is taken.
especially when exceptions are thrown from constructors and destructors.
using RAII may solve the problem if the exception is thrown by constructor.
but the ones thrown by destructors are truly problematic.

【在 z******i 的大作中提到】
: Performance problem.
: RTTI: dynamic cast is expensive
: exception: extra codes are generated for stack unwinding. Even if they are
: not used, extra code size means:
: 1. Load code from main memory to instruction cache. cache pollution.
: 2. CPU is pipe-lined, CPU still needs to decode the assembly codes.
: 3. In order to preserve stack, compiler might not be able to optimize the
: local variables to register. Big performance hit.

g*****y
发帖数: 7271
6
I actually quite disagree this opinion. When discussing the good/bad of
exception. You have to think about when you should use it? If it is not good
, what are the alternatives? Do the alternatives solve the problem of
exception?
You should use exception when you have errors that cause the function cannot
finish its task. For example, you cannot get the memory you need from new/
malloc. If you do not use exception, you usually return error code. You
still have different excution path for errors

【在 r*********r 的大作中提到】
: i think exception has a more damaging problem.
: that is, it will cause memory leak, when the exceptional path is taken.
: especially when exceptions are thrown from constructors and destructors.
: using RAII may solve the problem if the exception is thrown by constructor.
: but the ones thrown by destructors are truly problematic.

1 (共1页)
进入Programming版参与讨论
相关主题
What is wrong with the constructor calling?问一个constructor的问题 (转载)
[合集] C++ interview question help请教一下,exception时,destructor一定会被调用么?
急问:compile and build dependency请教个Bloomberg 的 C++ 题目
用包子呼唤大牛们--问关于C++Destructor的问题一个c++ constructor的问题, thanks
几个问题菜鸟请教smart pointer
请问C++ exception后如何清理function stack上的内存资源?一道编程题 - throw Exceptions
C++ 的 exception handlingTwo questions about handling exceptions in C++
C++: exception: out-of-order execution?一个Quant Developer的C++面试题
相关话题的讨论汇总
话题: exception话题: rtti话题: when话题: thrown