1
0
mirror of https://github.com/alliedmodders/hl2sdk.git synced 2025-09-19 03:56:10 +08:00

Update CRawAllacator to CMemAllocAllocator

This commit is contained in:
GAMMACASE
2025-08-01 21:46:39 +03:00
parent e181e1192a
commit d5c5ce5b2d

View File

@ -23,20 +23,24 @@
#include "memdbgon.h"
class CRawAllocator
class CMemAllocAllocator
{
public:
static void* Alloc( size_t nSize, size_t *nAdjustedSize )
template<typename T, typename I = int>
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<I>::max)() );
return ptr;
}
static void* Realloc( void *base, size_t nSize, size_t *nAdjustedSize )
template<typename T, typename I = int>
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<I>::max)() );
return ptr;
}