TPIE

11a2c2d
tpie::memory_manager Class Referencefinal

Memory management object used to track memory usage. More...

#include <tpie/memory.h>

Inherits tpie::resource_manager.

Public Types

enum  enforce_t { ENFORCE_IGNORE, ENFORCE_DEBUG, ENFORCE_WARN, ENFORCE_THROW }
 Memory limit enforcement policies. More...
 

Public Member Functions

 memory_manager ()
 
std::pair< uint8_t *, size_t > __allocate_consecutive (size_t upper_bound, size_t granularity)
 
void register_typed_allocation (size_t bytes, const std::type_info &t)
 
void register_typed_deallocation (size_t bytes, const std::type_info &t)
 
void register_allocation (size_t bytes, const std::type_info &t)
 
void register_deallocation (size_t bytes, const std::type_info &t)
 
std::string amount_with_unit (size_t amount) const override
 
void complain_about_unfreed_memory ()
 
std::unordered_map< std::type_index, memory_digest_itemmemory_digest ()
 
size_t used () const noexcept
 Return the current amount of the resource used. More...
 
size_t available () const noexcept
 Return the amount of the resource still available to be assigned. More...
 
size_t limit () const noexcept
 Return the resource limit. More...
 
void set_limit (size_t new_limit)
 Update the resource limit. More...
 
void set_enforcement (enforce_t e)
 Set the resource limit enforcement policy. More...
 
enforce_t enforcement () const noexcept
 Return the current resource limit enforcement policy. More...
 
void register_increased_usage (size_t amount)
 
void register_decreased_usage (size_t amount)
 

Protected Member Functions

void throw_out_of_resource_error (const std::string &s) override
 

Protected Attributes

std::atomic_size_t m_mutex
 
std::unordered_map< std::type_index, type_allocationsm_allocations
 
std::atomic< size_t > m_used
 
size_t m_limit
 
size_t m_maxExceeded
 
size_t m_nextWarning
 
enforce_t m_enforce
 
resource_type resource_managed
 

Detailed Description

Memory management object used to track memory usage.

Definition at line 62 of file memory.h.

Member Enumeration Documentation

◆ enforce_t

Memory limit enforcement policies.

Enumerator
ENFORCE_IGNORE 

Ignore when running out of the resource.

ENFORCE_DEBUG 

Log to debug log when the resource limit is exceeded.

Note that not all violations will be logged.

ENFORCE_WARN 

Log a warning when the resource limit is exceeded.

Note that not all violations will be logged.

ENFORCE_THROW 

Throw an out_of_resource_error when the resource limit is exceeded.

Definition at line 43 of file resource_manager.h.

43  {
54  };

Constructor & Destructor Documentation

◆ memory_manager()

tpie::memory_manager::memory_manager ( )

Construct the memory manager object.

Member Function Documentation

◆ __allocate_consecutive()

std::pair<uint8_t *, size_t> tpie::memory_manager::__allocate_consecutive ( size_t  upper_bound,
size_t  granularity 
)

Allocate the largest consecutive memory possible.

◆ available()

size_t tpie::resource_manager::available ( ) const
noexceptinherited

Return the amount of the resource still available to be assigned.

Referenced by tpie::ami::stream_old< T >::available_streams().

◆ enforcement()

enforce_t tpie::resource_manager::enforcement ( ) const
inlinenoexceptinherited

Return the current resource limit enforcement policy.

Definition at line 88 of file resource_manager.h.

88 {return m_enforce;}

◆ limit()

size_t tpie::resource_manager::limit ( ) const
inlinenoexceptinherited

Return the resource limit.

Definition at line 69 of file resource_manager.h.

69 {return m_limit;}

◆ set_enforcement()

void tpie::resource_manager::set_enforcement ( enforce_t  e)
inherited

Set the resource limit enforcement policy.

Parameters
eThe new enforcement policy.

◆ set_limit()

void tpie::resource_manager::set_limit ( size_t  new_limit)
inherited

Update the resource limit.

If the resource limit is exceeded by decreasing the limit, no exception will be thrown.

Parameters
new_limitThe new resource limit.

◆ used()

size_t tpie::resource_manager::used ( ) const
noexceptinherited

Return the current amount of the resource used.


The documentation for this class was generated from the following file:
tpie::resource_manager::ENFORCE_DEBUG
@ ENFORCE_DEBUG
Log to debug log when the resource limit is exceeded.
Definition: resource_manager.h:48
tpie::resource_manager::ENFORCE_WARN
@ ENFORCE_WARN
Log a warning when the resource limit is exceeded.
Definition: resource_manager.h:51
tpie::resource_manager::ENFORCE_THROW
@ ENFORCE_THROW
Throw an out_of_resource_error when the resource limit is exceeded.
Definition: resource_manager.h:53
tpie::resource_manager::ENFORCE_IGNORE
@ ENFORCE_IGNORE
Ignore when running out of the resource.
Definition: resource_manager.h:45