summaryrefslogtreecommitdiff
path: root/Runtime/Misc/AllocatorLabels.h
diff options
context:
space:
mode:
Diffstat (limited to 'Runtime/Misc/AllocatorLabels.h')
-rw-r--r--Runtime/Misc/AllocatorLabels.h72
1 files changed, 72 insertions, 0 deletions
diff --git a/Runtime/Misc/AllocatorLabels.h b/Runtime/Misc/AllocatorLabels.h
new file mode 100644
index 0000000..1c89d28
--- /dev/null
+++ b/Runtime/Misc/AllocatorLabels.h
@@ -0,0 +1,72 @@
+#ifndef ALLOCATORLABELS_H
+#define ALLOCATORLABELS_H
+
+#include "Runtime/Modules/ExportModules.h"
+
+#define ENABLE_MEM_PROFILER (ENABLE_MEMORY_MANAGER && ENABLE_PROFILER)
+#if ENABLE_MEM_PROFILER
+#define IF_MEMORY_PROFILER_ENABLED(x) x
+#else
+#define IF_MEMORY_PROFILER_ENABLED(x)
+#endif
+
+// Must be in Sync with ENUM WiiMemory in PlayerSettings.txt
+enum MemLabelIdentifier
+{
+#define DO_LABEL(Name) kMem##Name##Id ,
+#include "AllocatorLabelNames.h"
+#undef DO_LABEL
+ kMemLabelCount
+};
+
+struct AllocationRootReference;
+struct ProfilerAllocationHeader;
+
+
+struct EXPORT_COREMODULE MemLabelId {
+ MemLabelId() { IF_MEMORY_PROFILER_ENABLED( rootReference = NULL ); }
+ explicit MemLabelId ( MemLabelIdentifier id, ProfilerAllocationHeader* root ) : label(id) { IF_MEMORY_PROFILER_ENABLED( rootReference = NULL; SetRootHeader(root) ); }
+ void Initialize ( MemLabelIdentifier id ) { label = id; IF_MEMORY_PROFILER_ENABLED( rootReference = NULL ); }
+
+ MemLabelIdentifier label;
+
+#if ENABLE_MEM_PROFILER
+ MemLabelId ( const MemLabelId& other );
+ ~MemLabelId () { if(rootReference) ReleaseReference(); }
+
+ const MemLabelId& operator= (const MemLabelId& other);
+ void ReleaseReference();
+ ProfilerAllocationHeader* GetRootHeader () const;
+ void SetRootHeader ( ProfilerAllocationHeader* rootHeader );
+ bool UseAutoRoot () const { return rootReference == NULL; };
+private:
+ // root reference = NULL: use stack to get root
+ AllocationRootReference* rootReference;
+#else
+ ProfilerAllocationHeader* GetRootHeader () const {return NULL;}
+ void SetRootHeader ( ProfilerAllocationHeader* rootHeader ) {}
+#endif
+};
+
+#if ENABLE_MEM_PROFILER
+typedef const MemLabelId& MemLabelRef;
+#else
+typedef MemLabelId MemLabelRef;
+#endif
+
+#define DO_LABEL_STRUCT(Name) struct EXPORT_COREMODULE Name##Struct : public MemLabelId { }; extern EXPORT_COREMODULE Name##Struct Name;
+
+#define DO_LABEL(Name) DO_LABEL_STRUCT(kMem##Name)
+#include "AllocatorLabelNames.h"
+#undef DO_LABEL
+
+#undef DO_LABEL_STRUCT
+
+void InitializeMemoryLabels();
+
+//#if UNITY_ENABLE_ACCOUNTING_ALLOCATORS
+extern const char* const MemLabelName[];
+//#endif
+
+
+#endif