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