Skip to content
Better HN
Top
New
Best
Ask
Show
Jobs
Search
⌘K
undefined | Better HN
0 points
Gupie
5mo ago
0 comments
Share
Open a file in the constructor, close it in the destructor. RAII with 0 allocations.
0 comments
default
newest
oldest
dh2022
5mo ago
std::vector<int> allocated and freed on the stack will allocate an array for its int’s on the heap…
usefulcat
5mo ago
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
menaerus
5mo ago
WDYM? Vector is an abstraction over dynamically sized arrays so sure it does use heap to store its elements.
2 more replies
Gupie
OP
5mo ago
Sure, but my point was that RAII doesn't need to involve the heap. Another example would be acquiring abd releasing a mutex.
j
/
k
navigate · click thread line to collapse