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

#include <logger.h>

Public Member Functions

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

Detailed Description

A MemLogger logs memory allocation, deallocation, and errors.

This class here is merely used to define the functions needed to implement a MemLogger.

Member Function Documentation

◆ logAllocation()

virtual void cookmem::MemLogger::logAllocation ( void * userPtr,
std::size_t userSize,
MemAllocType_et allocType )
pure virtual

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()

virtual void cookmem::MemLogger::logDeallocation ( void * userPtr,
std::size_t userSize )
pure virtual

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()

virtual void cookmem::MemLogger::logError ( void * userPtr,
MemError_et error,
const char * message,
const char * file = __FILE__,
int line = __LINE__ )
pure virtual

Log an error that the memory pool detected: a double free (MEM_ERROR_DOUBLE_FREE), overwritten padding bytes (MEM_ERROR_PADDING), or an invalid padding size when the pool is created (MEM_ERROR_GENERAL). The loggers of CookMem throw Exception with the same error, message, file and line. A logger may record the error first, or throw its own exception. It is not safe to go on after an error, so if this function returns, the pool throws Exception itself.

Parameters
userPtrthe user pointer that had the error, or nullptr.
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.

◆ logFreeSegment()

virtual void cookmem::MemLogger::logFreeSegment ( void * segment,
std::size_t segmentSize )
pure virtual

Log the memory segment release.

Parameters
segmentthe segment released.
segmentSizethe segment size.

◆ logGetSegment()

virtual void cookmem::MemLogger::logGetSegment ( void * segment,
std::size_t segmentSize )
pure virtual

Log the memory segment allocation.

Parameters
segmentthe segment obtained.
segmentSizethe segment size.

◆ logReallocation()

virtual void cookmem::MemLogger::logReallocation ( void * userPtr,
std::size_t oldUserSize,
std::size_t newUserSize )
pure virtual

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()

virtual void cookmem::MemLogger::logTrimEmptySegments ( )
pure virtual

Log a pool empty-segment trimming pass.


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