std::declare_reachable(3)
π¦ std::declare_reachable π¦
okay so this is the std::declare_reachable(3) page from the C++ Standard Libary manual β and yes, the manual name up top really says βLibary,β Iβm not fixing it, bestie π. This whole page is about one little function that tells the runtime βhey, keep this object alive.β
πΈ NAME πΈ
std::declare_reachable β std::declare_reachable. Thatβs it. Thatβs the name. The manpage said it twice and honestly? Repetition is a vibe. Periodt. π
β¨ Synopsis β¨
Defined in header <memory>
void declare_reachable( void* p ); (since C++11)
(removed in C++23)
So itβs giving βsince C++11β and βremoved in C++23β β glow-up era, then departure era, no cap π.
Now the actual tea: declares the object referenced by the pointer p reachable. Reachable objects will not be deleted by the garbage collector or considered to be a leak by a leak detector even if all pointers to it are destroyed.
An object may be declared reachable multiple times, in which case multiple calls to std::undeclare_reachable would be needed to remove this property. For example, a XOR linked list needs to declare its nodes reachable if the implementation has garbage collection enabled.
bestie, the whole point is keeping stuff alive even when every pointer to it is gone β the garbage collector and the leak detector are looking at it like βnope, not touching that.β π«Ά
π Parameters π
pβ a safely-derived pointer or a null pointer.
π« Return value π«
(none) β literally no return value, itβs giving βI did the thing and Iβm not gonna report backβ energy. π
π Exceptions π
May throw std::bad_alloc if the system cannot allocate memory required to track reachable objects.
So if the system canβt allocate the memory it needs to track reachable objects, boom: std::bad_alloc. Keep that in mind, bestie. π
π See also π
std::undeclare_reachableβ declares that an object can be recycled (C++11) (function template) (removed in C++23).
source/version: http://cppreference.com Β· date 2024.06.10 Β· page std::declare_reachable(3) π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms