Cbeam
Loading...
Searching...
No Matches
cbeam::container::stable_reference_buffer::delay_deallocation Class Reference

Manages delayed deallocation of memory blocks in shared library contexts. More...

#include <stable_reference_buffer.hpp>

Public Member Functions

 delay_deallocation ()
 Begin a scope that prevents deallocation of memory created within it.
 
 ~delay_deallocation () noexcept
 Exit the protected scope, potentially leading to deallocation of memory.
 

Detailed Description

Manages delayed deallocation of memory blocks in shared library contexts.

Ensures that memory blocks remain valid even if their reference count drops to zero within the scope of this class. This capability is critical when shared libraries need to pass raw pointers back and forth, especially in cases where a library might be unloaded, but the memory it allocated is still in use. The stable_reference_buffer::safe_get() method complements this by safely retrieving raw pointers, ensuring that they are valid within the delay_deallocation scope, and returning nullptr if not to prevent unsafe access.

  • Scope-Based Management: Maintains memory buffer validity within delay_deallocation scope, allowing safe pointer access.
  • Use Case: Preserves the reference count of buffers even after the associated stable_reference_buffer instances are destructed, especially critical in scenarios involving the unloading of shared libraries.
  • Examples: Consult DelayDeallocationTest for practical implementations.

Best Practices

Constructor & Destructor Documentation

◆ delay_deallocation()

cbeam::container::stable_reference_buffer::delay_deallocation::delay_deallocation ( )
inline

Begin a scope that prevents deallocation of memory created within it.

◆ ~delay_deallocation()

cbeam::container::stable_reference_buffer::delay_deallocation::~delay_deallocation ( )
inlinenoexcept

Exit the protected scope, potentially leading to deallocation of memory.


The documentation for this class was generated from the following file: