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

Provides a Memory Page class base on Double-Linked List, which is the core of MemoryPool More...

Public Member Functions

 MemoryPage (intptr_t commitSize, intptr_t reserveSize)
 
bool IsAvailable () const
 Gets a value indicating whether the page has been created successfully More...
 
RLIB_RESTRICT_RETURN void * AllocByte (intptr_t RLIB_INTERNAL_DEBUG_PARAM)
 Allocates a block of memory from a memory page More...
 
void Collect (LPVOID)
 Frees a memory block allocated from a memory page More...
 
bool ReSize (LPVOID, intptr_t)
 Resizes a block of memory without moving, which enables you to resize a memory block More...
 
RLIB_RESTRICT_RETURN void * ReAlloc (LPVOID, intptr_t new_size=-1)
 Reallocates a block of memory, which enables you to resize a memory block and move it. If new_size equals -1, the original size is kept More...
 
intptr_t Shrink ()
 Trys to uncommit(return to the system) unused memory More...
 
RLIB_THREAD_SAFE intptr_t GetSize (LPCVOID)
 Gets the aligned size of memory allocated, More...
 
intptr_t GetUsage ()
 Gets the size of allocated memory More...
 
intptr_t GetMemorySize ()
 Gets the size of committed memory More...
 
intptr_t GetUnusedSize ()
 Gets the size of unallocated memory, no guarantee of continuity More...
 
intptr_t GetMaxAllocSize ()
 Gets the maximum size of available memory, no guarantee of accuracy as memory fragmentation More...
 
PTR_STATUS Validate (LPCVOID)
 Validate a pointer, and return zero if it belongs to current instance More...
 
void DumpToFile (const TCHAR *lpszFile)
 Dumps the entire pages into file for analysis More...
 

Public Attributes

 RLIB_DECLARE_DYNCREATE
 

Static Public Attributes

static intptr_t PageSize = static_cast<intptr_t>(MemoryAllocator::GetPageSize())
 

Protected Types

enum  PTR_STATUS { PTR_IN = 0, PTR_HIGH, PTR_LOW }
 
typedef struct BLOCK_INFO * PBLOCK_INFO
 

Protected Member Functions

PBLOCK_INFO find (intptr_t)
 
LPVOID alloc_block (intptr_t)
 
PBLOCK_INFO alloc_tail (PBLOCK_INFO, intptr_t, PBLOCK_INFO)
 
bool extend (intptr_t)
 
void init (intptr_t, intptr_t)
 
void free_block (PBLOCK_INFO)
 

Protected Attributes

PBLOCK_INFO m_base_ptr
 
PBLOCK_INFO m_first_ptr
 
PBLOCK_INFO m_last_ptr
 
intptr_t m_now
 
intptr_t m_used
 
intptr_t m_reserved
 

Friends

class MemoryPool
 

Detailed Description

Provides a Memory Page class base on Double-Linked List, which is the core of MemoryPool

Member Function Documentation

RLIB_RESTRICT_RETURN void * MemoryPage::AllocByte ( intptr_t  RLIB_INTERNAL_DEBUG_PARAM)

Allocates a block of memory from a memory page

Warning
the allocated memory is no guarantee to be initialized to zero
void MemoryPage::Collect ( LPVOID  lpuser)

Frees a memory block allocated from a memory page

void MemoryPage::DumpToFile ( const TCHAR *  lpszFile)

Dumps the entire pages into file for analysis

intptr_t MemoryPage::GetMaxAllocSize ( )

Gets the maximum size of available memory, no guarantee of accuracy as memory fragmentation

intptr_t MemoryPage::GetMemorySize ( )

Gets the size of committed memory

intptr_t MemoryPage::GetSize ( LPCVOID  user)

Gets the aligned size of memory allocated,

Warning
the function return unaligned size when defined(_DEBUG)
intptr_t MemoryPage::GetUnusedSize ( )

Gets the size of unallocated memory, no guarantee of continuity

intptr_t MemoryPage::GetUsage ( )

Gets the size of allocated memory

bool MemoryPage::IsAvailable ( ) const

Gets a value indicating whether the page has been created successfully

RLIB_RESTRICT_RETURN void * MemoryPage::ReAlloc ( LPVOID  lpuser,
intptr_t  new_size = -1 
)

Reallocates a block of memory, which enables you to resize a memory block and move it. If new_size equals -1, the original size is kept

Warning
the allocated memory is no guarantee to be initialized to zero
Returns
return nullptr if failed, and the original memory block is unaffected
bool MemoryPage::ReSize ( LPVOID  lpuser,
intptr_t  new_size 
)

Resizes a block of memory without moving, which enables you to resize a memory block

Warning
the allocated memory is no guarantee to be initialized to zero
intptr_t MemoryPage::Shrink ( )

Trys to uncommit(return to the system) unused memory

MemoryPage::PTR_STATUS MemoryPage::Validate ( LPCVOID  p)

Validate a pointer, and return zero if it belongs to current instance


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