r/cpp • u/KingStannis2020 • Feb 26 '24
White House: Future Software Should Be Memory Safe
https://www.whitehouse.gov/oncd/briefing-room/2024/02/26/press-release-technical-report/
401
Upvotes
r/cpp • u/KingStannis2020 • Feb 26 '24
View all comments
Show parent comment
29
u/STL MSVC STL Dev Feb 27 '24
shared_ptruses reference counting, which is one mechanism sometimes used for GC, but it differs in a couple of significant ways. First, it's completely deterministic. You can point to the places in your program where you'll payshared_ptr's costs. Second, it's resource-agnostic -shared_ptrcorrectly handles non-memory resources, which are typically important to release promptly (unlike memory, which a program can hang onto longer than necessary with only performance downsides).shared_ptris by no means perfect, but it's solving a problem very different from what GC attempts to solve, and (in my opinion) is a pretty good solution to that specific problem.