I have implemented a custom allocator (to be used by STL containers within my memory debugging utility, without them using my overridden new operator). Within the memory debugger I use an instance of the same allocator class to allocate the objects I need to keep track of 'normal' memory allocations. It's all working fine, but I'm not sure if the way I'm using the allocator interface is correct. Here are the utility methods as they currently stand (correct initialization parameters for the entry will be added soon):
iidebug::CMemoryDebugger::CEntry* iidebug::CMemoryDebugger::NewEntry()
{
CEntry* pEntry = m_entryAllocator.allocate(1);
if (0 != pEntry)
{
new(pEntry) CEntry(0, 0, __FILE__, 0, 0, 0);
}
return pEntry;
}
void iidebug::CMemoryDebugger::DeleteEntry( iidebug::CMemoryDebugger::CEntry* pEntry )
{
if (0 != pEntry)
{
destruct(pEntry);
m_entryAllocator.deallocate(pEntry, 1);
}
}
This just seems very messy, but I can't see how I can improve it.