2011-06-02 21:59:20 +02:00
|
|
|
// Copyright (c) 2008-2011 Raynaldo (Wildicv) Rivera, Joshua (Dark_Kilauea) Jones, Murat (wolfmanfx) Sari
|
|
|
|
// This file is part of the "cAudio Engine"
|
|
|
|
// For conditions of distribution and use, see copyright notice in cAudio.h
|
|
|
|
|
2011-05-29 20:33:24 +02:00
|
|
|
#pragma once
|
2011-05-19 06:36:14 +02:00
|
|
|
|
2011-06-05 21:23:53 +02:00
|
|
|
#include "cAudioDefines.h"
|
2011-05-19 06:36:14 +02:00
|
|
|
|
2011-06-02 21:59:20 +02:00
|
|
|
#if CAUDIO_USE_MEMORYTRACKER == 1
|
2011-05-19 06:36:14 +02:00
|
|
|
|
|
|
|
#include <map>
|
2011-06-05 21:23:53 +02:00
|
|
|
#include "cMutex.h"
|
2011-05-19 06:36:14 +02:00
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
namespace cAudio
|
|
|
|
{
|
|
|
|
//! Tracks all allocations that go through cAudio's memory system and keeps statistics on it
|
|
|
|
class cMemoryTracker
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
cMemoryTracker();
|
|
|
|
~cMemoryTracker();
|
|
|
|
|
|
|
|
static cMemoryTracker* Instance()
|
|
|
|
{
|
|
|
|
static cMemoryTracker Singleton;
|
|
|
|
return &Singleton;
|
|
|
|
}
|
|
|
|
|
|
|
|
//! Adds an allocation to be tracked
|
|
|
|
void AddAllocation(void* pointer, size_t size, const char* filename, int line, const char* function);
|
|
|
|
|
|
|
|
//! Removes a previously tracked allocation (for when it has been deallocated)
|
|
|
|
void RemoveAllocation(void* pointer);
|
|
|
|
|
|
|
|
private:
|
|
|
|
cAudioMutex Mutex;
|
|
|
|
|
|
|
|
struct cTrackedMemoryBlock
|
|
|
|
{
|
|
|
|
size_t size;
|
|
|
|
const char* filename;
|
|
|
|
int line;
|
|
|
|
const char* function;
|
|
|
|
};
|
|
|
|
|
|
|
|
std::map<void*, cTrackedMemoryBlock> TrackedBlocks;
|
|
|
|
|
2011-06-02 21:59:20 +02:00
|
|
|
#if CAUDIO_MEMORYTRACKER_GENERATE_STATISTICS == 1
|
2011-05-19 06:36:14 +02:00
|
|
|
struct Statistics
|
|
|
|
{
|
|
|
|
Statistics() : AllocationHighWaterMark(0), CurrentAllocationBytes(0),
|
|
|
|
TotalAllocationBytes(0), MaxNumAllocations(0),
|
|
|
|
CurrentNumAllocations(0), TotalNumAllocations(0)
|
|
|
|
{ }
|
|
|
|
size_t AllocationHighWaterMark;
|
|
|
|
size_t CurrentAllocationBytes;
|
|
|
|
size_t TotalAllocationBytes;
|
|
|
|
|
|
|
|
size_t MaxNumAllocations;
|
|
|
|
size_t CurrentNumAllocations;
|
|
|
|
size_t TotalNumAllocations;
|
|
|
|
} MemStats;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void DumpLeaks();
|
|
|
|
|
2011-06-02 21:59:20 +02:00
|
|
|
#if CAUDIO_MEMORYTRACKER_LOG_ALL_ALLOCATIONS == 1
|
2011-05-19 06:36:14 +02:00
|
|
|
std::ofstream outMemLog;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2011-05-29 20:33:24 +02:00
|
|
|
#endif
|