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 () |
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.
tpie::memory_manager::memory_manager | ( | ) |
Construct the memory manager object.
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.
|
inline |
|
inline |
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.
e | The 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.
new_limit | The new memory limit in bytes. |
size_t tpie::memory_manager::used | ( | ) | const | |
throw | ( | |||
) |
Return the current amount of memory used.