I'm wondering if RAII always allocates on the stack, or if the compiler ever uses the heap for large objects (and then perhaps adds a token to the stack as a sort of reminder of when to destroy the corresponding heap-allocated object)?
UPDATE: Apparently this question has been deemed unclear. Perhaps a code example will make this clearer:
In this code:
void dosomething() {
MyClass myclass();
}
Assuming the compiler didn't optimize away such a trivial example, does the instance of MyClass that's hereby created always get allocated on the stack, or is the heap ever used?
I think I understand the answer now thanks to the accepted answer -- the answer appears to be that the class instance itself goes on the stack while its contents may or may not depending on how its constructor was defined. Please add a comment/answer if this is incorrect.