Branimir Karadžić 11 年之前
父节点
当前提交
6d2d04cad5
共有 4 个文件被更改,包括 22 次插入15 次删除
  1. 1 1
      examples/common/entry/cmd.cpp
  2. 13 0
      examples/common/entry/entry.cpp
  3. 0 14
      examples/common/entry/entry.h
  4. 8 0
      examples/common/entry/entry_p.h

+ 1 - 1
examples/common/entry/cmd.cpp

@@ -12,7 +12,7 @@
 
 #include "dbg.h"
 #include "cmd.h"
-#include "entry.h" //TinyStlCustomAllocator
+#include "entry_p.h"
 
 #include <tinystl/allocator.h>
 #include <tinystl/string.h>

+ 13 - 0
examples/common/entry/entry.cpp

@@ -451,6 +451,19 @@ namespace entry
 		return &s_allocator;
 	}
 
+	void* TinyStlAllocator::static_allocate(size_t _bytes)
+	{
+		return BX_ALLOC(getAllocator(), _bytes);
+	}
+
+	void TinyStlAllocator::static_deallocate(void* _ptr, size_t /*_bytes*/)
+	{
+		if (NULL != _ptr)
+		{
+			BX_FREE(getAllocator(), _ptr);
+		}
+	}
+
 } // namespace entry
 
 extern "C" bool entry_process_events(uint32_t* _width, uint32_t* _height, uint32_t* _debug, uint32_t* _reset)

+ 0 - 14
examples/common/entry/entry.h

@@ -18,20 +18,6 @@ extern "C" int _main_(int _argc, char** _argv);
 #define ENTRY_WINDOW_FLAG_ASPECT_RATIO UINT32_C(0x00000001)
 #define ENTRY_WINDOW_FLAG_FRAME        UINT32_C(0x00000002)
 
-// For a custom tinystl allocator, define this and implement TinyStlCustomAllocator somewhere in the project.
-#ifndef ENTRY_CONFIG_USE_TINYSTL_CUSTOM_ALLOCATOR
-#	define ENTRY_CONFIG_USE_TINYSTL_CUSTOM_ALLOCATOR 0
-#endif // ENTRY_CONFIG_USE_TINYSTL
-
-#if ENTRY_CONFIG_USE_TINYSTL_CUSTOM_ALLOCATOR
-	struct TinyStlCustomAllocator
-	{
-		static void* static_allocate(size_t _bytes);
-		static void static_deallocate(void* _ptr, size_t /*_bytes*/);
-	};
-#	define TINYSTL_ALLOCATOR TinyStlCustomAllocator
-#endif //ENTRY_CONFIG_USE_TINYSTL_CUSTOM_ALLOCATOR
-
 namespace entry
 {
 	struct WindowHandle  { uint16_t idx; };

+ 8 - 0
examples/common/entry/entry_p.h

@@ -6,6 +6,8 @@
 #ifndef ENTRY_PRIVATE_H_HEADER_GUARD
 #define ENTRY_PRIVATE_H_HEADER_GUARD
 
+#define TINYSTL_ALLOCATOR entry::TinyStlAllocator
+
 #include <bx/spscqueue.h>
 
 #include "entry.h"
@@ -42,6 +44,12 @@
 
 namespace entry
 {
+	struct TinyStlAllocator
+	{
+		static void* static_allocate(size_t _bytes);
+		static void static_deallocate(void* _ptr, size_t /*_bytes*/);
+	};
+
 	int main(int _argc, char** _argv);
 
 	struct Event