ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
cloudViewer::ml::impl::MemoryAllocation Class Reference

A class for managing memory segments within a memory allocation. More...

#include <MemoryAllocation.h>

Public Member Functions

 MemoryAllocation (void *ptr, size_t size, size_t alignment=1)
 
template<class T >
std::pair< T *, size_t > Alloc (size_t size)
 
std::pair< void *, size_t > Alloc (size_t size)
 
std::pair< void *, size_t > AllocLargestSegment ()
 Returns the largest free segment. More...
 
template<class T >
void Free (const std::pair< T *, size_t > &segment)
 Frees a previously returned segment. More...
 
void Free (const std::pair< void *, size_t > &segment)
 Frees a previously returned segment. More...
 
size_t MaxUsed () const
 Returns the peak memory usage in bytes. More...
 
size_t Alignment () const
 Returns the alignment in bytes. More...
 
const std::vector< std::pair< void *, size_t > > & FreeSegments () const
 Returns the list of free segments. More...
 
void PrintFreeSegments () const
 Prints all free segments. Meant for debugging. More...
 

Static Public Member Functions

template<class T >
static void PrintSegment (const std::pair< T *, size_t > &s)
 Prints the segment. Meant for debugging. More...
 

Detailed Description

A class for managing memory segments within a memory allocation.

Definition at line 21 of file MemoryAllocation.h.

Constructor & Destructor Documentation

◆ MemoryAllocation()

cloudViewer::ml::impl::MemoryAllocation::MemoryAllocation ( void *  ptr,
size_t  size,
size_t  alignment = 1 
)
inline

Creates a MemoryAllocation object that manages memory segments within a memory allocation.

Parameters
ptrPointer to the beginning of the memory.
sizeSize of the memory.
alignmentThe alignment for returned segments.

Definition at line 30 of file MemoryAllocation.h.

References size.

Member Function Documentation

◆ Alignment()

size_t cloudViewer::ml::impl::MemoryAllocation::Alignment ( ) const
inline

Returns the alignment in bytes.

Definition at line 148 of file MemoryAllocation.h.

◆ Alloc() [1/2]

template<class T >
std::pair<T*, size_t> cloudViewer::ml::impl::MemoryAllocation::Alloc ( size_t  size)
inline

Returns a memory segment with size for type T. Returns the pointer and the size in number of elements T. May return the pair (nullptr,0) if the allocation is not possible.

Definition at line 48 of file MemoryAllocation.h.

References size.

Referenced by AllocLargestSegment().

◆ Alloc() [2/2]

std::pair<void*, size_t> cloudViewer::ml::impl::MemoryAllocation::Alloc ( size_t  size)
inline

Returns a memory segment with size in bytes. May return the pair (nullptr,0) if the allocation is not possible.

Definition at line 55 of file MemoryAllocation.h.

References size.

◆ AllocLargestSegment()

std::pair<void*, size_t> cloudViewer::ml::impl::MemoryAllocation::AllocLargestSegment ( )
inline

Returns the largest free segment.

Definition at line 75 of file MemoryAllocation.h.

References Alloc(), and size.

◆ Free() [1/2]

template<class T >
void cloudViewer::ml::impl::MemoryAllocation::Free ( const std::pair< T *, size_t > &  segment)
inline

Frees a previously returned segment.

Definition at line 85 of file MemoryAllocation.h.

References size.

◆ Free() [2/2]

void cloudViewer::ml::impl::MemoryAllocation::Free ( const std::pair< void *, size_t > &  segment)
inline

Frees a previously returned segment.

Definition at line 93 of file MemoryAllocation.h.

References count.

◆ FreeSegments()

const std::vector<std::pair<void*, size_t> >& cloudViewer::ml::impl::MemoryAllocation::FreeSegments ( ) const
inline

Returns the list of free segments.

Definition at line 151 of file MemoryAllocation.h.

◆ MaxUsed()

size_t cloudViewer::ml::impl::MemoryAllocation::MaxUsed ( ) const
inline

Returns the peak memory usage in bytes.

Definition at line 145 of file MemoryAllocation.h.

◆ PrintFreeSegments()

void cloudViewer::ml::impl::MemoryAllocation::PrintFreeSegments ( ) const
inline

Prints all free segments. Meant for debugging.

Definition at line 163 of file MemoryAllocation.h.

References PrintSegment().

◆ PrintSegment()

template<class T >
static void cloudViewer::ml::impl::MemoryAllocation::PrintSegment ( const std::pair< T *, size_t > &  s)
inlinestatic

Prints the segment. Meant for debugging.

Definition at line 157 of file MemoryAllocation.h.

Referenced by PrintFreeSegments().


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