logoalt Hacker News

WD-4212/07/20254 repliesview on HN

0 allocations after the program initializes.


Replies

tialaramex12/07/2025

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.

Gupie12/07/2025

Open a file in the constructor, close it in the destructor. RAII with 0 allocations.

show 1 reply
nicoburns12/07/2025

RAII doesn't necessarily require allocation?

jjmarr12/07/2025

Stack "allocations" are basically free.

show 1 reply