logoalt Hacker News

dh202212/08/20252 repliesview on HN

std::vector<int> allocated and freed on the stack will allocate an array for its int’s on the heap…


Replies

usefulcat12/08/2025

I've heard that MSVC does (did?) that, but if so that's an MSVC problem. gcc and clang don't do that.

https://godbolt.org/z/nasoWeq5M

show 1 reply
Gupie12/08/2025

Sure, but my point was that RAII doesn't need to involve the heap. Another example would be acquiring abd releasing a mutex.