ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
cloudViewer::core::MemoryCache Class Reference

Public Member Functions

 MemoryCache ()=default
 
 MemoryCache (const MemoryCache &)=delete
 
MemoryCacheoperator= (const MemoryCache &)=delete
 
void * Malloc (size_t byte_size)
 
void Free (void *ptr)
 
void Acquire (void *ptr, size_t byte_size, const std::shared_ptr< MemoryManagerDevice > &device_mm)
 Acquires ownership of the new real allocated blocks. More...
 
std::vector< std::pair< void *, std::shared_ptr< MemoryManagerDevice > > > Release (size_t byte_size)
 
std::vector< std::pair< void *, std::shared_ptr< MemoryManagerDevice > > > ReleaseAll ()
 Releases ownership of all unused real allocated blocks. More...
 
size_t Size () const
 Returns the number of allocated real blocks. More...
 
bool Empty () const
 True if the set of allocated real blocks is empty, false otherwise. More...
 

Static Public Member Functions

static size_t AlignByteSize (size_t byte_size, size_t alignment=8)
 

Detailed Description

Definition at line 78 of file MemoryManagerCached.cpp.

Constructor & Destructor Documentation

◆ MemoryCache() [1/2]

cloudViewer::core::MemoryCache::MemoryCache ( )
default

◆ MemoryCache() [2/2]

cloudViewer::core::MemoryCache::MemoryCache ( const MemoryCache )
delete

Member Function Documentation

◆ Acquire()

void cloudViewer::core::MemoryCache::Acquire ( void *  ptr,
size_t  byte_size,
const std::shared_ptr< MemoryManagerDevice > &  device_mm 
)
inline

Acquires ownership of the new real allocated blocks.

Definition at line 211 of file MemoryManagerCached.cpp.

◆ AlignByteSize()

static size_t cloudViewer::core::MemoryCache::AlignByteSize ( size_t  byte_size,
size_t  alignment = 8 
)
inlinestatic

Computes an internal byte size that ensures a proper alignment of the real and virtual blocks.

Definition at line 86 of file MemoryManagerCached.cpp.

Referenced by cloudViewer::core::Cacher::Malloc().

◆ Empty()

bool cloudViewer::core::MemoryCache::Empty ( ) const
inline

True if the set of allocated real blocks is empty, false otherwise.

Definition at line 280 of file MemoryManagerCached.cpp.

References Size().

◆ Free()

void cloudViewer::core::MemoryCache::Free ( void *  ptr)
inline

Frees memory by moving the corresponding block to the set of free virtual blocks. Consecutive free virtual blocks belonging to the same real block are merged together.

Definition at line 132 of file MemoryManagerCached.cpp.

References LogError.

◆ Malloc()

void* cloudViewer::core::MemoryCache::Malloc ( size_t  byte_size)
inline

Allocates memory from the set of free virtual blocks. Returns nullptr if no suitable block was found.

Definition at line 92 of file MemoryManagerCached.cpp.

◆ operator=()

MemoryCache& cloudViewer::core::MemoryCache::operator= ( const MemoryCache )
delete

◆ Release()

std::vector<std::pair<void*, std::shared_ptr<MemoryManagerDevice> > > cloudViewer::core::MemoryCache::Release ( size_t  byte_size)
inline

Releases ownership of unused real allocated blocks whose sizes sum up to the requested byte size. Strategy:

  • Best single fit: argmin_x { x.byte_size_ >= byte_size }.
  • If not found, use next-best fit and repeat.

Definition at line 230 of file MemoryManagerCached.cpp.

Referenced by ReleaseAll().

◆ ReleaseAll()

std::vector<std::pair<void*, std::shared_ptr<MemoryManagerDevice> > > cloudViewer::core::MemoryCache::ReleaseAll ( )
inline

Releases ownership of all unused real allocated blocks.

Definition at line 272 of file MemoryManagerCached.cpp.

References max(), and Release().

◆ Size()

size_t cloudViewer::core::MemoryCache::Size ( ) const
inline

Returns the number of allocated real blocks.

Definition at line 277 of file MemoryManagerCached.cpp.

Referenced by Empty().


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