cAudio  2.3.0
3d Audio Engine
cMemoryTracker.h
1 // Copyright (c) 2008-2011 Raynaldo (Wildicv) Rivera, Joshua (Dark_Kilauea) Jones, Murat (wolfmanfx) Sari
2 // This file is part of the "cAudio Engine"
3 // For conditions of distribution and use, see copyright notice in cAudio.h
4 
5 #pragma once
6 
7 #include "cAudioDefines.h"
8 
9 #if CAUDIO_USE_MEMORYTRACKER == 1
10 
11 #include <map>
12 #include "cMutex.h"
13 #include <iostream>
14 #include <fstream>
15 
16 namespace cAudio
17 {
19  class cMemoryTracker
20  {
21  public:
22  cMemoryTracker();
23  ~cMemoryTracker();
24 
25  static cMemoryTracker* Instance()
26  {
27  static cMemoryTracker Singleton;
28  return &Singleton;
29  }
30 
32  void AddAllocation(void* pointer, size_t size, const char* filename, int line, const char* function);
33 
35  void RemoveAllocation(void* pointer);
36 
37  private:
38  cAudioMutex Mutex;
39 
40  struct cTrackedMemoryBlock
41  {
42  size_t size;
43  const char* filename;
44  int line;
45  const char* function;
46  };
47 
48  std::map<void*, cTrackedMemoryBlock> TrackedBlocks;
49 
50 #if CAUDIO_MEMORYTRACKER_GENERATE_STATISTICS == 1
51  struct Statistics
52  {
53  Statistics() : AllocationHighWaterMark(0), CurrentAllocationBytes(0),
54  TotalAllocationBytes(0), MaxNumAllocations(0),
55  CurrentNumAllocations(0), TotalNumAllocations(0)
56  { }
57  size_t AllocationHighWaterMark;
58  size_t CurrentAllocationBytes;
59  size_t TotalAllocationBytes;
60 
61  size_t MaxNumAllocations;
62  size_t CurrentNumAllocations;
63  size_t TotalNumAllocations;
64  } MemStats;
65 #endif
66 
67  void DumpLeaks();
68 
69 #if CAUDIO_MEMORYTRACKER_LOG_ALL_ALLOCATIONS == 1
70  std::ofstream outMemLog;
71 #endif
72  };
73 };
74 
75 #endif
cAudio
Main namespace for the entire cAudio library.
Definition: cAudioCapture.h:15