Optimize localized string allocation

This commit is contained in:
momo5502
2016-07-22 12:52:12 +02:00
parent cc74cf4d8d
commit a343c5ac5b
8 changed files with 90 additions and 68 deletions

View File

@ -15,10 +15,10 @@ namespace Utils
}
~Allocator()
{
this->Free();
this->Clear();
}
void Free()
void Clear()
{
for (auto i = this->RefMemory.begin(); i != this->RefMemory.end(); ++i)
{
@ -38,6 +38,28 @@ namespace Utils
this->Pool.clear();
}
void Free(void* data)
{
auto i = this->RefMemory.find(data);
if (i != this->RefMemory.end())
{
i->second(i->first);
this->RefMemory.erase(i);
}
auto j = std::find(this->Pool.begin(), this->Pool.end(), data);
if (j != this->Pool.end())
{
Memory::Free(data);
this->Pool.erase(j);
}
}
void Free(const void* data)
{
this->Free(const_cast<void*>(data));
}
void Reference(void* memory, FreeCallback callback)
{
this->RefMemory[memory] = callback;