Skip to content
Better HN
Top
Best
Ask
Show
New
Jobs
Search
⌘K
0 points
Gupie
6mo ago
0 comments
Save
Share
Open a file in the constructor, close it in the destructor. RAII with 0 allocations.
0 comments
4 comments · 1 top-level
top
newest
oldest
dh2022
6mo ago
· 3 in thread
std::vector<int> allocated and freed on the stack will allocate an array for its int’s on the heap…
usefulcat
6mo 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
6mo 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
6mo 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