Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
roc::core::MemoryLimiter Class Reference

Memory limiter. This class can be used to keep track of memory being consumed. This is done through the acquire and release methods. The class is used within classes such as LimitedPool, LimitedArena. More...

#include <memory_limiter.h>

Inheritance diagram for roc::core::MemoryLimiter:
Collaboration diagram for roc::core::MemoryLimiter:

Public Member Functions

 MemoryLimiter (const char *name, size_t max_bytes)
 Initialize memory limiter. max_bytes is the maximum total amount of memory that can be acquired. If 0, then there is no limit, in which case, only tracking will be performed. More...
 
 ~MemoryLimiter ()
 Destroy memory limiter. This will panic if memory is still tracked as acquired. More...
 
ROC_ATTR_NODISCARD bool acquire (size_t num_bytes)
 Track acquired memory. More...
 
void release (size_t num_bytes)
 Track released memory. This will panic if we are releasing more than what is currently acquired. More...
 
size_t num_acquired ()
 Get number of bytes currently acquired. More...
 

Detailed Description

Memory limiter. This class can be used to keep track of memory being consumed. This is done through the acquire and release methods. The class is used within classes such as LimitedPool, LimitedArena.

Definition at line 27 of file memory_limiter.h.

Constructor & Destructor Documentation

◆ MemoryLimiter()

roc::core::MemoryLimiter::MemoryLimiter ( const char *  name,
size_t  max_bytes 
)
explicit

Initialize memory limiter. max_bytes is the maximum total amount of memory that can be acquired. If 0, then there is no limit, in which case, only tracking will be performed.

◆ ~MemoryLimiter()

roc::core::MemoryLimiter::~MemoryLimiter ( )

Destroy memory limiter. This will panic if memory is still tracked as acquired.

Member Function Documentation

◆ acquire()

ROC_ATTR_NODISCARD bool roc::core::MemoryLimiter::acquire ( size_t  num_bytes)

Track acquired memory.

Returns
true if successful i.e. maximum limit not breached.

◆ num_acquired()

size_t roc::core::MemoryLimiter::num_acquired ( )

Get number of bytes currently acquired.

◆ release()

void roc::core::MemoryLimiter::release ( size_t  num_bytes)

Track released memory. This will panic if we are releasing more than what is currently acquired.


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