iw4x-client/src/Utils/Memory.cpp

39 lines
582 B
C++
Raw Normal View History

2016-01-12 13:08:26 -05:00
#include "STDInclude.hpp"
namespace Utils
{
void* Memory::Allocate(size_t length)
{
void* data = new char[length];
2016-06-08 11:28:58 -04:00
assert(data != nullptr);
2016-01-12 13:08:26 -05:00
if (data)
{
ZeroMemory(data, length);
}
return data;
}
char* Memory::DuplicateString(std::string string)
{
char* newString = Memory::AllocateArray<char>(string.size() + 1);
2016-06-19 11:40:30 -04:00
std::memcpy(newString, string.data(), string.size());
2016-01-12 13:08:26 -05:00
return newString;
}
void Memory::Free(void* data)
{
2016-06-08 11:28:58 -04:00
if (data)
{
delete[] data;
}
2016-01-12 13:08:26 -05:00
}
void Memory::Free(const void* data)
{
Memory::Free(const_cast<void*>(data));
2016-01-12 13:08:26 -05:00
}
}