Yes, the answer depends on the compiler.
A quick experiment with my compiler ( g++ 4.4.3 ) shows that its runtime library first tries to malloc save memory for an exception and, otherwise, tries to allocate space within the "emergency buffer" of the entire system, a data segment. If this does not work, it calls std::terminate() .
It seems that the main task of the emergency buffer is to throw std::bad_alloc after the process std::bad_alloc from the heap space (in this case, the malloc call failed).
Corresponding __cxa_allocate_exception function:
extern "C" void * __cxxabiv1::__cxa_allocate_exception(std::size_t thrown_size) throw() { void *ret; thrown_size += sizeof (__cxa_refcounted_exception); ret = malloc (thrown_size); if (! ret) { __gnu_cxx::__scoped_lock sentry(emergency_mutex); bitmask_type used = emergency_used; unsigned int which = 0; if (thrown_size > EMERGENCY_OBJ_SIZE) goto failed; while (used & 1) { used >>= 1; if (++which >= EMERGENCY_OBJ_COUNT) goto failed; } emergency_used |= (bitmask_type)1 << which; ret = &emergency_buffer[which][0]; failed:; if (!ret) std::terminate (); }
I do not know how typical this scheme is.
NPE Jul 07 2018-11-11T00: 00Z
source share