FML
Public Types | Public Member Functions
FML::LogAllocator< T > Struct Template Reference

Custom allocator that logs allocations. More...

#include <MemoryLogging.h>

Public Types

using value_type = T
 

Public Member Functions

 LogAllocator ()=default
 
template<class U >
 LogAllocator (const LogAllocator< U > &)
 
T * allocate (std::size_t size)
 
void deallocate (T *ptr, std::size_t size)
 

Detailed Description

template<typename T>
struct FML::LogAllocator< T >

Custom allocator that logs allocations.

Definition at line 278 of file MemoryLogging.h.

Member Typedef Documentation

◆ value_type

template<typename T >
using FML::LogAllocator< T >::value_type = T

Definition at line 279 of file MemoryLogging.h.

Constructor & Destructor Documentation

◆ LogAllocator() [1/2]

template<typename T >
FML::LogAllocator< T >::LogAllocator ( )
default

◆ LogAllocator() [2/2]

template<typename T >
template<class U >
FML::LogAllocator< T >::LogAllocator ( const LogAllocator< U > &  )
inline

Definition at line 283 of file MemoryLogging.h.

283{}

Member Function Documentation

◆ allocate()

template<typename T >
T * FML::LogAllocator< T >::allocate ( std::size_t  size)
inline

Definition at line 285 of file MemoryLogging.h.

285 {
286 if (size <= std::numeric_limits<std::size_t>::max() / sizeof(T)) {
287 if (auto ptr = std::malloc(size * sizeof(T))) {
288 MemoryLog::get()->add(ptr, size * sizeof(T));
289 return static_cast<T *>(ptr);
290 }
291 }
292 std::cout << "[LogAllocator] Allocation of " << size << " elements of type " << typeid(T).name()
293 << " of size " << sizeof(T) << " failed" << std::endl;
294 throw std::bad_alloc();
295 }
static MemoryLog * get()
Definition: MemoryLogging.h:86
void add(void *ptr, size_t size)

◆ deallocate()

template<typename T >
void FML::LogAllocator< T >::deallocate ( T *  ptr,
std::size_t  size 
)
inline

Definition at line 296 of file MemoryLogging.h.

296 {
297 MemoryLog::get()->remove(ptr, size * sizeof(T));
298 std::free(ptr);
299 }
void free(HaloModel **hm)
Definition: Wrapper.cpp:34
void remove(void *ptr, size_t size)

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