开发者

In which memory area are exception classes instances created?

I could not find the information where are exception class instances created during exception handling ? In which memory area (stack, heap, static storage, etc.) ? I assume it is not on th开发者_开发技巧e stack because of stack-unwinding ...


From the standard:

15.2.4: The memory for the temporary copy of the exception being thrown is allocated in an unspecified way, except as noted in 3.7.3.1.

And 3.7.3.1 says:

3.7.3.1: All objects which neither have dynamic storage duration nor are local have static storage duration. The storage for these objects shall last for the duration of the program (3.6.2, 3.6.3).


The answer is "in a mysterious area managed by the compiler" - seriously, the standard doesn't specify where they must be stored.


Is kitchen quoted from the standard, it is unspecified. Most implementations allocate them from heap, as they need to survive the stack unwinding process, which may remove stack frames (when throwing outside a function) or create new ones (calling destructors etc). GCC uses built-in function __cxa_allocate_exception for allocating the memory.


Exceptions are always thrown by value so no problem even if allocated on stack

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜