개요

std::exception은 스택과 힙 어디에서 할당될까

분석

Untitled

throw를 작성하고 어셈을 확인하자.

Untitled

  1. __cxa_allocate_exception() 을 호출하여 할당한다
  2. std::exception 생성자를 호출한다
  3. exception의 타입에 대한 정보를 매개변수 레지스터에 담는다
  4. __cxa_throw를 호출하여 throw 루틴을 수행한다

떡하니 __cxa_allocate_exception()으로 할당한다고 한다. 컴파일러 내부 함수인듯 하니 찾아가자.

Untitled

귀찮으니 구글에 대충 치면 나온다

Untitled

__cxa_allocate_exception 함수 내용을 확인하자. 내부에서 __aligned_malloc_with_fallback()을 호출한다.

즉 힙에서 malloc하는 거다.