TPIE

v1.1rc1-6-g0c97303
tpie::memory_manager Class Reference

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

#include <tpie/memory.h>

Public Types

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

Public Member Functions

size_t used () const throw ()
 Return the current amount of memory used. More...
 
size_t available () const throw ()
 Return the amount of memory still available to allocation. More...
 
size_t limit () const throw ()
 Return the memory limit. More...
 
void set_limit (size_t new_limit)
 Update the memory limit. More...
 
void set_enforcement (enforce_t e)
 Set the memory limit enforcement policy. More...
 
enforce_t enforcement ()
 Return the current memory limit enforcement policy. More...
 
void register_allocation (size_t bytes)
 
void register_deallocation (size_t bytes)
 
 memory_manager ()
 
std::pair< uint8_t *, size_t > __allocate_consecutive (size_t upper_bound, size_t granularity)
 
void register_pointer (void *p, size_t size, const std::type_info &t)
 
void unregister_pointer (void *p, size_t size, const std::type_info &t)
 
void assert_tpie_ptr (void *p)
 
void complain_about_unfreed_memory ()
 

Detailed Description

Memory management object used to track memory usage.

Definition at line 58 of file memory.h.

Member Enumeration Documentation

Memory limit enforcement policies.

Enumerator
ENFORCE_IGNORE 

Ignore when running out of memory.

ENFORCE_DEBUG 

Log to debug log when the memory limit is exceeded.

Note that not all violations will be logged.

ENFORCE_WARN 

Log a warning when the memory limit is exceeded.

Note that not all violations will be logged.

ENFORCE_THROW 

Throw an out_of_memory_error when the memory limit is exceeded.

Definition at line 63 of file memory.h.

63  {
74  };
Ignore when running out of memory.
Definition: memory.h:65
Throw an out_of_memory_error when the memory limit is exceeded.
Definition: memory.h:73
Log to debug log when the memory limit is exceeded.
Definition: memory.h:68
Log a warning when the memory limit is exceeded.
Definition: memory.h:71

Constructor & Destructor Documentation

tpie::memory_manager::memory_manager ( )

Construct the memory manager object.

Member Function Documentation

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

Allocate the largest consecutive memory possible.

size_t tpie::memory_manager::available ( ) const
throw (
)

Return the amount of memory still available to allocation.

enforce_t tpie::memory_manager::enforcement ( )
inline

Return the current memory limit enforcement policy.

Definition at line 108 of file memory.h.

108 {return m_enforce;}
size_t tpie::memory_manager::limit ( ) const
throw (
)
inline

Return the memory limit.

Definition at line 89 of file memory.h.

89 {return m_limit;}
void tpie::memory_manager::register_allocation ( size_t  bytes)

Register that more memory has been used. Possibly throws a warning or an exception if the memory limit is exceeded, depending on the enforcement.

void tpie::memory_manager::register_deallocation ( size_t  bytes)

Register that some memory has been freed.

Referenced by tpie::tpie_delete(), and tpie::tpie_delete_array().

void tpie::memory_manager::set_enforcement ( enforce_t  e)

Set the memory limit enforcement policy.

Parameters
eThe new enforcement policy.
void tpie::memory_manager::set_limit ( size_t  new_limit)

Update the memory limit.

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

Parameters
new_limitThe new memory limit in bytes.
size_t tpie::memory_manager::used ( ) const
throw (
)

Return the current amount of memory used.


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