text
stringlengths
0
2.2M
{
allocator.Free(p);
}
else
{
PlatformFree(p);
}
}
}
class EASTLTestICA : public EA::Allocator::ICoreAllocator
{
public:
EASTLTestICA()
{
}
virtual ~EASTLTestICA()
{
}
virtual void* Alloc(size_t size, const char* name, unsigned int flags)
{
return ::InternalMalloc(size, name, (int)flags, 0, NULL, 0);
}
virtual void* Alloc(size_t size, const char* name, unsigned int flags,
unsigned int align, unsigned int)
{
return ::InternalMalloc(size, (size_t)align, name, (int)flags, 0, NULL, 0);
}
virtual void Free(void* pData, size_t /*size*/)
{
return ::InternalFree(pData);
}
};
EA::Allocator::ICoreAllocator* EA::Allocator::ICoreAllocator::GetDefaultAllocator()
{
static EASTLTestICA sEASTLTestICA;
return &sEASTLTestICA;
}
///////////////////////////////////////////////////////////////////////////
// operator new/delete implementations
//
_Ret_maybenull_ _Post_writable_byte_size_(size) void* operator new(size_t size, const std::nothrow_t&) EA_THROW_SPEC_NEW_NONE()
{
return InternalMalloc(size);
}
void operator delete(void* p, const std::nothrow_t&) EA_THROW_SPEC_DELETE_NONE()
{
if(p) // The standard specifies that 'delete NULL' is a valid operation.
{
gEASTLTest_AllocationCount--;
InternalFree(p);
}
}
_Ret_maybenull_ _Post_writable_byte_size_(size) void* operator new[](size_t size, const std::nothrow_t&) EA_THROW_SPEC_NEW_NONE()
{
gEASTLTest_AllocationCount++;
gEASTLTest_TotalAllocationCount++;
void* p = InternalMalloc(size);
return p;
}
void operator delete[](void* p, const std::nothrow_t&) EA_THROW_SPEC_DELETE_NONE()
{
if(p)
{
gEASTLTest_AllocationCount--;
InternalFree(p);
}
}
_Ret_notnull_ _Post_writable_byte_size_(size) void* operator new(size_t size)
{
gEASTLTest_AllocationCount++;
gEASTLTest_TotalAllocationCount++;
void* mem = InternalMalloc(size);
#if !defined(EA_COMPILER_NO_EXCEPTIONS)
if (mem == NULL)
{
throw std::bad_alloc();
}
#endif
return mem;
}