Browse Source

Better way to configure entry allocator.

Branimir Karadžić 10 years ago
parent
commit
0ff1d7df0c
2 changed files with 15 additions and 5 deletions
  1. 12 2
      examples/common/entry/entry.cpp
  2. 3 3
      examples/common/entry/entry_p.h

+ 12 - 2
examples/common/entry/entry.cpp

@@ -22,7 +22,17 @@ namespace entry
 	static bool s_exit = false;
 	static bool s_exit = false;
 	static bx::FileReaderI* s_fileReader = NULL;
 	static bx::FileReaderI* s_fileReader = NULL;
 	static bx::FileWriterI* s_fileWriter = NULL;
 	static bx::FileWriterI* s_fileWriter = NULL;
-	static ENTRY_CONFIG_ALLOCATOR s_allocator;
+
+	extern bx::ReallocatorI* getDefaultAllocator();
+	static bx::ReallocatorI* s_allocator = getDefaultAllocator();
+
+#if ENTRY_CONFIG_IMPLEMENT_DEFAULT_ALLOCATOR
+	bx::ReallocatorI* getDefaultAllocator()
+	{
+		static bx::CrtAllocator s_allocator;
+		return &s_allocator;
+	}
+#endif // ENTRY_CONFIG_IMPLEMENT_DEFAULT_ALLOCATOR
 
 
 	bool setOrToggle(uint32_t& _flags, const char* _name, uint32_t _bit, int _first, int _argc, char const* const* _argv)
 	bool setOrToggle(uint32_t& _flags, const char* _name, uint32_t _bit, int _first, int _argc, char const* const* _argv)
 	{
 	{
@@ -455,7 +465,7 @@ namespace entry
 
 
 	bx::ReallocatorI* getAllocator()
 	bx::ReallocatorI* getAllocator()
 	{
 	{
-		return &s_allocator;
+		return s_allocator;
 	}
 	}
 
 
 	void* TinyStlAllocator::static_allocate(size_t _bytes)
 	void* TinyStlAllocator::static_allocate(size_t _bytes)

+ 3 - 3
examples/common/entry/entry_p.h

@@ -39,9 +39,9 @@
 #	error "Both ENTRY_DEFAULT_WIDTH and ENTRY_DEFAULT_HEIGHT must be defined."
 #	error "Both ENTRY_DEFAULT_WIDTH and ENTRY_DEFAULT_HEIGHT must be defined."
 #endif // ENTRY_DEFAULT_WIDTH
 #endif // ENTRY_DEFAULT_WIDTH
 
 
-#ifndef ENTRY_CONFIG_ALLOCATOR
-#	define ENTRY_CONFIG_ALLOCATOR bx::CrtAllocator
-#endif // ENTRY_CONFIG_ALLOCATOR
+#ifndef ENTRY_CONFIG_IMPLEMENT_DEFAULT_ALLOCATOR
+#	define ENTRY_CONFIG_IMPLEMENT_DEFAULT_ALLOCATOR 1
+#endif // ENTRY_CONFIG_IMPLEMENT_DEFAULT_ALLOCATOR
 
 
 #define ENTRY_IMPLEMENT_EVENT(_class, _type) \
 #define ENTRY_IMPLEMENT_EVENT(_class, _type) \
 			_class(WindowHandle _handle) : Event(_type, _handle) {}
 			_class(WindowHandle _handle) : Event(_type, _handle) {}