From 112b53b116a2195842850f38596bc5f060af9946 Mon Sep 17 00:00:00 2001 From: Dario Manesku Date: Wed, 21 Jan 2015 18:01:32 +0100 Subject: [PATCH] Added possibility to override default tinystl allocator for 'example-common' project. --- examples/common/bgfx_utils.cpp | 2 ++ examples/common/common.h | 19 +++++++++++++++++++ examples/common/entry/cmd.cpp | 1 + examples/common/entry/entry_windows.cpp | 1 + examples/common/entry/input.cpp | 1 + 5 files changed, 24 insertions(+) diff --git a/examples/common/bgfx_utils.cpp b/examples/common/bgfx_utils.cpp index a9516af1..0035076d 100644 --- a/examples/common/bgfx_utils.cpp +++ b/examples/common/bgfx_utils.cpp @@ -5,6 +5,8 @@ #include // strlen +#include "common.h" + #include #include #include diff --git a/examples/common/common.h b/examples/common/common.h index fbcea73c..0f2a4a1d 100644 --- a/examples/common/common.h +++ b/examples/common/common.h @@ -3,7 +3,26 @@ * License: http://www.opensource.org/licenses/BSD-2-Clause */ +#ifndef COMMON_H_HEADER_GUARD +#define COMMON_H_HEADER_GUARD + #include #include #include "entry/entry.h" + +// For a custom tinystl allocator, define this and implement TinyStlCustomAllocator somewhere in the project. +#ifndef COMMON_CONFIG_USE_TINYSTL_CUSTOM_ALLOCATOR +# define COMMON_CONFIG_USE_TINYSTL_CUSTOM_ALLOCATOR 0 +#endif // COMMON_CONFIG_USE_TINYSTL + +#if COMMON_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 //COMMON_CONFIG_USE_TINYSTL_CUSTOM_ALLOCATOR + +#endif // COMMON_H_HEADER_GUARD diff --git a/examples/common/entry/cmd.cpp b/examples/common/entry/cmd.cpp index 6dfcb37d..7464176d 100644 --- a/examples/common/entry/cmd.cpp +++ b/examples/common/entry/cmd.cpp @@ -10,6 +10,7 @@ #include #include +#include "../common.h" #include "dbg.h" #include "cmd.h" diff --git a/examples/common/entry/entry_windows.cpp b/examples/common/entry/entry_windows.cpp index 1b3f4f2d..27944129 100644 --- a/examples/common/entry/entry_windows.cpp +++ b/examples/common/entry/entry_windows.cpp @@ -4,6 +4,7 @@ */ #include "entry_p.h" +#include "../common.h" #if ENTRY_CONFIG_USE_NATIVE && BX_PLATFORM_WINDOWS diff --git a/examples/common/entry/input.cpp b/examples/common/entry/input.cpp index 851f2264..ecfeb055 100644 --- a/examples/common/entry/input.cpp +++ b/examples/common/entry/input.cpp @@ -5,6 +5,7 @@ #include +#include "../common.h" #include "entry_p.h" #include "input.h"