From f0ddd0749982a318629cd4d03bbb5f9a0076f23d Mon Sep 17 00:00:00 2001 From: GAMMACASE <31375974+GAMMACASE@users.noreply.github.com> Date: Fri, 1 Aug 2025 21:46:39 +0300 Subject: [PATCH] Update CRawAllacator to CMemAllocAllocator --- public/tier1/rawallocator.h | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/public/tier1/rawallocator.h b/public/tier1/rawallocator.h index c347faaa..3aa0e4c3 100644 --- a/public/tier1/rawallocator.h +++ b/public/tier1/rawallocator.h @@ -23,20 +23,24 @@ #include "memdbgon.h" -class CRawAllocator +class CMemAllocAllocator { public: - static void* Alloc( size_t nSize, size_t *nAdjustedSize ) + template + static T* Alloc( I nCount, I &nAdjustedCount ) { - void *ptr = malloc( nSize ); - *nAdjustedSize = MAX( _msize( ptr ), nSize ); + size_t byte_size = nCount * sizeof( T ); + T *ptr = (T *)malloc( byte_size ); + nAdjustedCount = MIN( (I)(MAX( _msize( ptr ), byte_size ) / sizeof( T )), (std::numeric_limits::max)() ); return ptr; } - static void* Realloc( void *base, size_t nSize, size_t *nAdjustedSize ) + template + static T* Realloc( T *base, I nCount, I &nAdjustedCount ) { - void *ptr = realloc( base, nSize ); - *nAdjustedSize = MAX( _msize( ptr ), nSize ); + size_t byte_size = nCount * sizeof( T ); + T *ptr = (T *)realloc( base, byte_size ); + nAdjustedCount = MIN( (I)(MAX( _msize( ptr ), byte_size ) / sizeof( T )), (std::numeric_limits::max)() ); return ptr; }