Merge pull request #596 from diamante0018/refactor/memory
[Memory]: Remove nullptr check before std::free
This commit is contained in:
commit
a277640ed9
@ -4,7 +4,7 @@ namespace Utils
|
||||
{
|
||||
Utils::Memory::Allocator Memory::MemAllocator;
|
||||
|
||||
void* Memory::AllocateAlign(size_t length, size_t alignment)
|
||||
void* Memory::AllocateAlign(std::size_t length, std::size_t alignment)
|
||||
{
|
||||
auto* data = _aligned_malloc(length, alignment);
|
||||
assert(data);
|
||||
@ -12,9 +12,9 @@ namespace Utils
|
||||
return data;
|
||||
}
|
||||
|
||||
void* Memory::Allocate(size_t length)
|
||||
void* Memory::Allocate(std::size_t length)
|
||||
{
|
||||
auto* data = calloc(length, 1);
|
||||
auto* data = std::calloc(length, 1);
|
||||
assert(data);
|
||||
return data;
|
||||
}
|
||||
@ -28,10 +28,7 @@ namespace Utils
|
||||
|
||||
void Memory::Free(void* data)
|
||||
{
|
||||
if (data)
|
||||
{
|
||||
::free(data);
|
||||
}
|
||||
std::free(data);
|
||||
}
|
||||
|
||||
void Memory::Free(const void* data)
|
||||
@ -53,11 +50,11 @@ namespace Utils
|
||||
}
|
||||
|
||||
// Complementary function for memset, which checks if memory is filled with a char
|
||||
bool Memory::IsSet(void* mem, char chr, size_t length)
|
||||
bool Memory::IsSet(void* mem, char chr, std::size_t length)
|
||||
{
|
||||
auto* memArr = static_cast<char*>(mem);
|
||||
|
||||
for (size_t i = 0; i < length; ++i)
|
||||
for (std::size_t i = 0; i < length; ++i)
|
||||
{
|
||||
if (memArr[i] != chr)
|
||||
{
|
||||
|
@ -73,7 +73,7 @@ namespace Utils
|
||||
this->refMemory[memory] = callback;
|
||||
}
|
||||
|
||||
void* allocate(size_t length)
|
||||
void* allocate(std::size_t length)
|
||||
{
|
||||
std::lock_guard _(this->mutex);
|
||||
|
||||
@ -87,7 +87,7 @@ namespace Utils
|
||||
return this->allocateArray<T>(1);
|
||||
}
|
||||
|
||||
template <typename T> T* allocateArray(size_t count = 1)
|
||||
template <typename T> T* allocateArray(std::size_t count = 1)
|
||||
{
|
||||
return static_cast<T*>(this->allocate(count * sizeof(T)));
|
||||
}
|
||||
@ -133,13 +133,13 @@ namespace Utils
|
||||
std::unordered_map<void*, FreeCallback> refMemory;
|
||||
};
|
||||
|
||||
static void* AllocateAlign(size_t length, size_t alignment);
|
||||
static void* Allocate(size_t length);
|
||||
static void* AllocateAlign(std::size_t length, std::size_t alignment);
|
||||
static void* Allocate(std::size_t length);
|
||||
template <typename T> static T* Allocate()
|
||||
{
|
||||
return AllocateArray<T>(1);
|
||||
}
|
||||
template <typename T> static T* AllocateArray(size_t count = 1)
|
||||
template <typename T> static T* AllocateArray(std::size_t count = 1)
|
||||
{
|
||||
return static_cast<T*>(Allocate(count * sizeof(T)));
|
||||
}
|
||||
@ -159,7 +159,7 @@ namespace Utils
|
||||
static void FreeAlign(void* data);
|
||||
static void FreeAlign(const void* data);
|
||||
|
||||
static bool IsSet(void* mem, char chr, size_t length);
|
||||
static bool IsSet(void* mem, char chr, std::size_t length);
|
||||
|
||||
static bool IsBadReadPtr(const void* ptr);
|
||||
static bool IsBadCodePtr(const void* ptr);
|
||||
|
Loading…
Reference in New Issue
Block a user