RLib  5.7
RLib - an opensource, lightweight and multi-platform framework for cpp programming
System::IO::MemoryPool Class Reference

A nonblocking thread-safe memory-pool implementation More...

Classes

struct  MEMORY_PAGE
 

Public Types

typedef struct System::IO::MemoryPool::MEMORY_PAGEPMEMPAGE
 

Public Member Functions

 MemoryPool (intptr_t memory_count=RLIB_PAGECOUNT)
 
RLIB_RESTRICT_RETURN void * AllocByte (intptr_t size RLIB_INTERNAL_DEBUG_PARAM)
 Allocates memory, with debug information if provided [RLIB_INTERNAL_DEBUG_PARAM_HERE] More...
 
void Collect (void *lptr)
 Releases memory More...
 
bool ReSize (void *lptr, intptr_t new_size)
 Trys to change the size of memory allocated, if succeed and the new size is greater than the old size, the data in the expanded memory is undefined. More...
 
intptr_t GetSize (void *lptr)
 Gets the size of specified memory, More...
 
RLIB_RESTRICT_RETURN void * ReAlloc (void *lptr, intptr_t size)
 Reallocates memory, copys and releases original memory if succeed More...
 
RLIB_RESTRICT_RETURN void * TryReAlloc (void *lptr, intptr_t size)
 First, trys reallocate memory on the same page, if failed, the function behaves like ReAlloc More...
 
intptr_t GetUsage ()
 Gets the total size of allocated memory, no guarantee of accuracy More...
 
intptr_t GetMemorySize ()
 Gets the total size of committed memory, no guarantee of accuracy More...
 
intptr_t TryGCCollect ()
 Trys to collect unused memory and return to system if possible More...
 
intptr_t WaitForFullGCComplete ()
 Forces to collect unused memory and return to system, and waits until all collect tasks are completed More...
 
MEMORY_PAGEoperator[] (intptr_t index)
 Gets the associated MemoryPage object by index More...
 

Static Public Member Functions

static void SetBreakAlloc (__int64 lBreakAlloc)
 Sets a breakpoint on a specified object allocation order number(DEBUG only), which allows you to perform memory leak detection by breaking at a specific point of memory allocation, and tracing back to the origin of the request More...
 

Public Attributes

PMEMPAGE MemoryList
 
intptr_t MemoryCount
 
 RLIB_DECLARE_DYNCREATE
 

Detailed Description

A nonblocking thread-safe memory-pool implementation

Member Function Documentation

RLIB_RESTRICT_RETURN void * MemoryPool::AllocByte ( intptr_t size  RLIB_INTERNAL_DEBUG_PARAM)

Allocates memory, with debug information if provided [RLIB_INTERNAL_DEBUG_PARAM_HERE]

void MemoryPool::Collect ( void *  lptr)

Releases memory

intptr_t MemoryPool::GetMemorySize ( )

Gets the total size of committed memory, no guarantee of accuracy

intptr_t MemoryPool::GetSize ( void *  lptr)

Gets the size of specified memory,

Warning
in DEBUG version the return value is original unaligned size, while in RELEASE version is aligned.
intptr_t MemoryPool::GetUsage ( )

Gets the total size of allocated memory, no guarantee of accuracy

MEMORY_PAGE& System::IO::MemoryPool::operator[] ( intptr_t  index)
inline

Gets the associated MemoryPage object by index

Warning
no grantee of thread-safe, uses SyncRoot to sync
RLIB_RESTRICT_RETURN void * MemoryPool::ReAlloc ( void *  lptr,
intptr_t  size 
)

Reallocates memory, copys and releases original memory if succeed

bool MemoryPool::ReSize ( void *  lptr,
intptr_t  new_size 
)

Trys to change the size of memory allocated, if succeed and the new size is greater than the old size, the data in the expanded memory is undefined.

void MemoryPool::SetBreakAlloc ( __int64  lBreakAlloc)
static

Sets a breakpoint on a specified object allocation order number(DEBUG only), which allows you to perform memory leak detection by breaking at a specific point of memory allocation, and tracing back to the origin of the request

intptr_t MemoryPool::TryGCCollect ( )

Trys to collect unused memory and return to system if possible

RLIB_RESTRICT_RETURN void * MemoryPool::TryReAlloc ( void *  lptr,
intptr_t  size 
)

First, trys reallocate memory on the same page, if failed, the function behaves like ReAlloc

intptr_t MemoryPool::WaitForFullGCComplete ( )

Forces to collect unused memory and return to system, and waits until all collect tasks are completed


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