CookMem 1.6.0
A C++ memory context / allocator
Loading...
Searching...
No Matches
cookmem::StatsLogger Class Reference

#include <logger.h>

Public Member Functions

void logTrimEmptySegments ()
void logGetSegment (void *segment, std::size_t segmentSize)
void logFreeSegment (void *segment, std::size_t segmentSize)
void logAllocation (void *userPtr, std::size_t userSize, MemAllocType_et allocType)
void logReallocation (void *userPtr, std::size_t oldUserSize, std::size_t newUserSize)
void logDeallocation (void *userPtr, std::size_t userSize)
void logError (void *, MemError_et error, const char *message, const char *file=__FILE__, int line=__LINE__)
MemStatistics & getStats ()
const MemStatistics & getStats () const

Detailed Description

A MemLogger that tracks allocation and segment usage statistics.

This class implements the interface of MemLogger without explicitly inheriting from it. This is to avoid the overhead of virtual function calls and allows inlining of the functions.

Member Function Documentation

◆ getStats() [1/2]

MemStatistics & cookmem::StatsLogger::getStats ( )
inline

Get the statistics.

Returns
the statistics gathered so far.

◆ getStats() [2/2]

const MemStatistics & cookmem::StatsLogger::getStats ( ) const
inline

Get the statistics.

Returns
the statistics gathered so far.

◆ logAllocation()

void cookmem::StatsLogger::logAllocation ( void * userPtr,
std::size_t userSize,
MemAllocType_et allocType )
inline

Log the memory allocation.

Parameters
userPtrthe user pointer allocated, or nullptr if the allocation failed.
userSizethe size of the allocation, as getSize () reports it: the requested size if the exact size is stored, and otherwise the requested size rounded up to the alignment. If the allocation failed, the requested size.
allocTypethe type of the allocation.

◆ logDeallocation()

void cookmem::StatsLogger::logDeallocation ( void * userPtr,
std::size_t userSize )
inline

Log the memory deallocation.

Parameters
userPtrthe user pointer allocated.
userSizethe size of the allocation, as getSize () reports it, which is the size its allocation was logged with.

◆ logError()

void cookmem::StatsLogger::logError ( void * ,
MemError_et error,
const char * message,
const char * file = __FILE__,
int line = __LINE__ )
inline

Report a memory error by throwing an exception.

Parameters
errorthe type of the error encountered.
messagea description of the error.
filethe source file where the error was detected.
linethe line number where the error was detected.
Exceptions
Exceptionalways.

◆ logFreeSegment()

void cookmem::StatsLogger::logFreeSegment ( void * segment,
std::size_t segmentSize )
inline

Log the memory segment release.

Parameters
segmentthe segment released.
segmentSizethe segment size.

◆ logGetSegment()

void cookmem::StatsLogger::logGetSegment ( void * segment,
std::size_t segmentSize )
inline

Log the memory segment allocation.

Parameters
segmentthe segment obtained.
segmentSizethe segment size.

◆ logReallocation()

void cookmem::StatsLogger::logReallocation ( void * userPtr,
std::size_t oldUserSize,
std::size_t newUserSize )
inline

Log a reallocation in place, which grows or shrinks an allocation without moving it. A reallocation that moves the memory is logged as an allocation and a deallocation instead.

Parameters
userPtrthe user pointer, which does not change.
oldUserSizethe size before, as getSize () reported it.
newUserSizethe size after, as getSize () reports it.

◆ logTrimEmptySegments()

void cookmem::StatsLogger::logTrimEmptySegments ( )
inline

Log a pool empty-segment trimming pass.


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