mirror of
https://github.com/alliedmodders/hl2sdk.git
synced 2025-09-19 20:16:10 +08:00
Update CRawAllacator to CMemAllocAllocator
This commit is contained in:
@ -23,20 +23,24 @@
|
|||||||
|
|
||||||
#include "memdbgon.h"
|
#include "memdbgon.h"
|
||||||
|
|
||||||
class CRawAllocator
|
class CMemAllocAllocator
|
||||||
{
|
{
|
||||||
public:
|
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 );
|
size_t byte_size = nCount * sizeof( T );
|
||||||
*nAdjustedSize = MAX( _msize( ptr ), nSize );
|
T *ptr = (T *)malloc( byte_size );
|
||||||
|
nAdjustedCount = MIN( (I)(MAX( _msize( ptr ), byte_size ) / sizeof( T )), (std::numeric_limits<I>::max)() );
|
||||||
return ptr;
|
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 );
|
size_t byte_size = nCount * sizeof( T );
|
||||||
*nAdjustedSize = MAX( _msize( ptr ), nSize );
|
T *ptr = (T *)realloc( base, byte_size );
|
||||||
|
nAdjustedCount = MIN( (I)(MAX( _msize( ptr ), byte_size ) / sizeof( T )), (std::numeric_limits<I>::max)() );
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user