Re:The C++ standard for the F-35 Fighter Jet [video]
by jandrewrogers on Sunday December 07, 2025 @01:36PM
(#46183904)
What does RAII have to do with any of the above?
[ Parent
| on HN ]
Re:The C++ standard for the F-35 Fighter Jet [video]
by WD-42 on Sunday December 07, 2025 @01:47PM
(#46183995)
0 allocations after the program initializes.
Re:The C++ standard for the F-35 Fighter Jet [video]
by tialaramex on Sunday December 07, 2025 @02:03PM
(#46184129)
RAII doesn't imply allocating.
My guess is that you're assuming all user defined types, and maybe even all non-trivial built-in types too, are boxed, meaning they're allocated on the heap when we create them.
That's not the case in C++ (the language in question here) and it's rarely the case in other modern languages because it has terrible performance qualities.
Re:The C++ standard for the F-35 Fighter Jet [video]
by Gupie on Sunday December 07, 2025 @01:56PM
(#46184067)
Open a file in the constructor, close it in the destructor. RAII with 0 allocations.
Re:The C++ standard for the F-35 Fighter Jet [video]
by dh2022 on Sunday December 07, 2025 @09:37PM
(#46187701)
std::vector<int> allocated and freed on the stack will allocate an array for its int’s on the heap…
Re:The C++ standard for the F-35 Fighter Jet [video]
by usefulcat on Monday December 08, 2025 @01:41AM
(#46189144)
I've heard that MSVC does (did?) that, but if so that's an MSVC problem. gcc and clang don't do that.
Re:The C++ standard for the F-35 Fighter Jet [video]
by menaerus on Monday December 08, 2025 @03:00AM
(#46189608)
WDYM? Vector is an abstraction over dynamically sized arrays so sure it does use heap to store its elements.
Re:The C++ standard for the F-35 Fighter Jet [video]
by aw1621107 on Monday December 08, 2025 @01:32PM
(#46195886)
I think usefulcat interpreted "std::vector<int> allocated and freed on the stack" as creating a default std::vector<int> and then destroying it without pushing elements to it. That's what their godbolt link shows, at least, though to be fair MSVC seems to match the described GCC/Clang behavior these days.
Re:The C++ standard for the F-35 Fighter Jet [video]
by Gupie on Monday December 08, 2025 @10:39AM
(#46193524)
Sure, but my point was that RAII doesn't need to involve the heap. Another example would be acquiring abd releasing a mutex.
Re:The C++ standard for the F-35 Fighter Jet [video]
by jjmarr on Sunday December 07, 2025 @02:29PM
(#46184331)
Stack "allocations" are basically free.
Re:The C++ standard for the F-35 Fighter Jet [video]
by grougnax on Monday December 08, 2025 @03:49AM
(#46189939)
No. And they're unsafe. Avoid them at all costs.
Re:The C++ standard for the F-35 Fighter Jet [video]
by nicoburns on Sunday December 07, 2025 @01:56PM
(#46184066)
RAII doesn't necessarily require allocation?
Re:The C++ standard for the F-35 Fighter Jet [video]
by DashAnimal on Sunday December 07, 2025 @01:59PM
(#46184097)
Well if you're using the standard library then you're not really paying attention to allocations and deallocations for one. For instance, the use of std::string. So I guess I'm wondering if you work in an industry that avoids std?
Re:The C++ standard for the F-35 Fighter Jet [video]
by jandrewrogers on Sunday December 07, 2025 @03:19PM
(#46184756)
I work in high-scale data infrastructure. It is common practice to do no memory allocation after bootstrap. Much of the standard library is still available despite this, though there are other reasons to not use the standard containers. For example, it is common to need containers that can be paged to storage across process boundaries.
C++ is designed to make this pretty easy.
Re:The C++ standard for the F-35 Fighter Jet [video]
by nmhancoc on Sunday December 07, 2025 @01:56PM
(#46184069)
Not an expert but I’m pretty sure no exceptions means you can’t use significant parts of std algorithm or the std containers.
And if you’re using pooling I think RAII gets significantly trickier to do.
Re:The C++ standard for the F-35 Fighter Jet [video]
by theICEBeardk on Sunday December 07, 2025 @02:29PM
(#46184330)
https://en.cppreference.com/w/cpp/freestanding.html to see the parts you can use.