Squashed 'external/gainput/' content from commit 2be0a50

git-subtree-dir: external/gainput
git-subtree-split: 2be0a50089eafcc6fccb66142180082e48f27f4c
This commit is contained in:
Simone
2024-01-22 08:51:55 +01:00
commit 4e42229bdd
170 changed files with 31921 additions and 0 deletions

View File

@@ -0,0 +1,58 @@
#include <gainput/gainput.h>
#include <gainput/GainputLog.h>
namespace gainput
{
DefaultAllocator&
GetDefaultAllocator()
{
static DefaultAllocator da;
return da;
}
TrackingAllocator::TrackingAllocator(Allocator& backingAllocator, Allocator& internalAllocator)
: backingAllocator_(backingAllocator),
internalAllocator_(internalAllocator),
allocations_(internalAllocator.New<HashMap<void*, size_t> >(internalAllocator)),
allocateCount_(0),
deallocateCount_(0),
allocatedMemory_(0)
{
}
TrackingAllocator::~TrackingAllocator()
{
internalAllocator_.Delete(allocations_);
}
void* TrackingAllocator::Allocate(size_t size, size_t align)
{
void* ptr = backingAllocator_.Allocate(size, align);
(*allocations_)[ptr] = size;
++allocateCount_;
allocatedMemory_ += size;
return ptr;
}
void TrackingAllocator::Deallocate(void* ptr)
{
HashMap<void*, size_t>::iterator it = allocations_->find(ptr);
if (it == allocations_->end())
{
GAINPUT_LOG("Warning: Trying to deallocate unknown memory block: %p\n", ptr);
}
else
{
allocatedMemory_ -= it->second;
allocations_->erase(it);
}
++deallocateCount_;
backingAllocator_.Deallocate(ptr);
}
}