High-performance memory pool allocator for graphics data. More...
#include <memory_pool.h>
Classes | |
struct | MemoryBlock |
Public Member Functions | |
void * | Allocate (size_t size) |
Allocate memory block of specified size. | |
void | Deallocate (void *ptr) |
Deallocate memory block. | |
void * | AllocateAligned (size_t size, size_t alignment) |
Allocate memory block aligned to specified boundary. | |
std::pair< size_t, size_t > | GetMemoryStats () const |
Get memory usage statistics. | |
std::pair< size_t, size_t > | GetAllocationStats () const |
Get allocation statistics. | |
void | Clear () |
Clear all allocated blocks (for cleanup) | |
Static Public Member Functions | |
static MemoryPool & | Get () |
Private Member Functions | |
MemoryPool () | |
~MemoryPool () | |
MemoryBlock * | FindFreeBlock (size_t size) |
void | InitializeBlockPool (std::vector< MemoryBlock > &pool, size_t block_size, size_t count) |
size_t | GetPoolIndex (size_t size) const |
Private Attributes | |
std::vector< MemoryBlock > | small_blocks_ |
std::vector< MemoryBlock > | medium_blocks_ |
std::vector< MemoryBlock > | large_blocks_ |
std::vector< MemoryBlock > | huge_blocks_ |
std::unordered_map< void *, MemoryBlock * > | allocated_blocks_ |
size_t | total_allocations_ |
size_t | total_deallocations_ |
size_t | total_used_bytes_ |
size_t | total_allocated_bytes_ |
Static Private Attributes | |
static constexpr size_t | kSmallBlockSize = 1024 |
static constexpr size_t | kMediumBlockSize |
static constexpr size_t | kLargeBlockSize |
static constexpr size_t | kHugeBlockSize |
High-performance memory pool allocator for graphics data.
The MemoryPool class provides efficient memory management for graphics operations in the YAZE ROM hacking editor. It reduces memory fragmentation and allocation overhead through pre-allocated memory blocks.
Key Features:
Performance Optimizations:
ROM Hacking Specific:
Definition at line 38 of file memory_pool.h.
|
private |
Definition at line 17 of file memory_pool.cc.
References huge_blocks_, InitializeBlockPool(), kHugeBlockSize, kLargeBlockSize, kMediumBlockSize, kSmallBlockSize, large_blocks_, medium_blocks_, small_blocks_, and total_allocated_bytes_.
|
private |
Definition at line 30 of file memory_pool.cc.
References Clear().
|
static |
Definition at line 12 of file memory_pool.cc.
Referenced by yaze::gfx::PoolAllocator< T >::allocate(), yaze::gfx::PerformanceDashboard::CollectMetrics(), yaze::gfx::PoolAllocator< T >::deallocate(), yaze::gfx::PerformanceProfiler::GenerateReport(), yaze::gfx::PerformanceDashboard::RenderMemoryUsage(), yaze::gfx::GraphicsOptimizationBenchmarks::SetUp(), yaze::gfx::TEST_F(), yaze::gfx::TEST_F(), and yaze::gfx::PerformanceDashboard::UpdateOptimizationStatus().
void * yaze::gfx::MemoryPool::Allocate | ( | size_t | size | ) |
Allocate memory block of specified size.
size | Size in bytes |
Definition at line 34 of file memory_pool.cc.
References allocated_blocks_, yaze::gfx::MemoryPool::MemoryBlock::data, FindFreeBlock(), yaze::gfx::MemoryPool::MemoryBlock::in_use, yaze::gfx::MemoryPool::MemoryBlock::size, total_allocations_, and total_used_bytes_.
Referenced by yaze::gfx::PoolAllocator< T >::allocate(), and AllocateAligned().
void yaze::gfx::MemoryPool::Deallocate | ( | void * | ptr | ) |
Deallocate memory block.
ptr | Pointer to memory block to deallocate |
Definition at line 55 of file memory_pool.cc.
References allocated_blocks_, yaze::gfx::MemoryPool::MemoryBlock::in_use, yaze::gfx::MemoryPool::MemoryBlock::size, total_deallocations_, and total_used_bytes_.
Referenced by yaze::gfx::PoolAllocator< T >::deallocate().
void * yaze::gfx::MemoryPool::AllocateAligned | ( | size_t | size, |
size_t | alignment | ||
) |
Allocate memory block aligned to specified boundary.
size | Size in bytes |
alignment | Alignment boundary (must be power of 2) |
Definition at line 76 of file memory_pool.cc.
References Allocate().
std::pair< size_t, size_t > yaze::gfx::MemoryPool::GetMemoryStats | ( | ) | const |
Get memory usage statistics.
Definition at line 91 of file memory_pool.cc.
References total_allocated_bytes_, and total_used_bytes_.
Referenced by yaze::gfx::PerformanceDashboard::CollectMetrics(), yaze::gfx::PerformanceProfiler::GenerateReport(), yaze::gfx::PerformanceDashboard::RenderMemoryUsage(), and yaze::gfx::PerformanceDashboard::UpdateOptimizationStatus().
std::pair< size_t, size_t > yaze::gfx::MemoryPool::GetAllocationStats | ( | ) | const |
Get allocation statistics.
Definition at line 95 of file memory_pool.cc.
References total_allocations_, and total_deallocations_.
void yaze::gfx::MemoryPool::Clear | ( | ) |
Clear all allocated blocks (for cleanup)
Definition at line 99 of file memory_pool.cc.
References allocated_blocks_, huge_blocks_, large_blocks_, medium_blocks_, small_blocks_, and total_used_bytes_.
Referenced by ~MemoryPool().
|
private |
Definition at line 118 of file memory_pool.cc.
References GetPoolIndex(), huge_blocks_, large_blocks_, medium_blocks_, and small_blocks_.
Referenced by Allocate().
|
private |
Definition at line 139 of file memory_pool.cc.
Referenced by MemoryPool().
|
private |
Definition at line 151 of file memory_pool.cc.
References kHugeBlockSize, kLargeBlockSize, kMediumBlockSize, and kSmallBlockSize.
Referenced by FindFreeBlock().
|
staticconstexprprivate |
Definition at line 95 of file memory_pool.h.
Referenced by GetPoolIndex(), and MemoryPool().
|
staticconstexprprivate |
Definition at line 96 of file memory_pool.h.
Referenced by GetPoolIndex(), and MemoryPool().
|
staticconstexprprivate |
Definition at line 98 of file memory_pool.h.
Referenced by GetPoolIndex(), and MemoryPool().
|
staticconstexprprivate |
Definition at line 100 of file memory_pool.h.
Referenced by GetPoolIndex(), and MemoryPool().
|
private |
Definition at line 104 of file memory_pool.h.
Referenced by Clear(), FindFreeBlock(), and MemoryPool().
|
private |
Definition at line 105 of file memory_pool.h.
Referenced by Clear(), FindFreeBlock(), and MemoryPool().
|
private |
Definition at line 106 of file memory_pool.h.
Referenced by Clear(), FindFreeBlock(), and MemoryPool().
|
private |
Definition at line 107 of file memory_pool.h.
Referenced by Clear(), FindFreeBlock(), and MemoryPool().
|
private |
Definition at line 110 of file memory_pool.h.
Referenced by Allocate(), Clear(), and Deallocate().
|
private |
Definition at line 111 of file memory_pool.h.
Referenced by Allocate(), and GetAllocationStats().
|
private |
Definition at line 112 of file memory_pool.h.
Referenced by Deallocate(), and GetAllocationStats().
|
private |
Definition at line 113 of file memory_pool.h.
Referenced by Allocate(), Clear(), Deallocate(), and GetMemoryStats().
|
private |
Definition at line 114 of file memory_pool.h.
Referenced by GetMemoryStats(), and MemoryPool().