From f19eca0905389586d4a171bba3e044cf3357eef6 Mon Sep 17 00:00:00 2001 From: smatz Date: Mon, 11 Feb 2008 20:23:38 +0000 Subject: [PATCH] (svn r12115) -Codechange: move malloc/realloc error messages to separate file to spare 4-8kB of binary size --- projects/openttd_vs80.vcproj | 8 ++++++-- projects/openttd_vs90.vcproj | 8 ++++++-- source.list | 1 + src/core/alloc_func.cpp | 24 ++++++++++++++++++++++++ src/core/alloc_func.hpp | 15 ++++++++++++--- 5 files changed, 49 insertions(+), 7 deletions(-) create mode 100644 src/core/alloc_func.cpp diff --git a/projects/openttd_vs80.vcproj b/projects/openttd_vs80.vcproj index ee2543eb5a..903f979ffb 100644 --- a/projects/openttd_vs80.vcproj +++ b/projects/openttd_vs80.vcproj @@ -455,6 +455,10 @@ RelativePath=".\..\src\airport.cpp" > + + @@ -920,7 +924,7 @@ > + + @@ -917,7 +921,7 @@ > FORCEINLINE T* MallocT(size_t num_elements) if (num_elements == 0) return NULL; T *t_ptr = (T*)malloc(num_elements * sizeof(T)); - if (t_ptr == NULL) error("Out of memory. Cannot allocate %i bytes", num_elements * sizeof(T)); + if (t_ptr == NULL) MallocError(num_elements * sizeof(T)); return t_ptr; } @@ -49,7 +58,7 @@ template FORCEINLINE T* CallocT(size_t num_elements) if (num_elements == 0) return NULL; T *t_ptr = (T*)calloc(num_elements, sizeof(T)); - if (t_ptr == NULL) error("Out of memory. Cannot allocate %i bytes", num_elements * sizeof(T)); + if (t_ptr == NULL) MallocError(num_elements * sizeof(T)); return t_ptr; } @@ -77,7 +86,7 @@ template FORCEINLINE T* ReallocT(T *t_ptr, size_t num_elements) } t_ptr = (T*)realloc(t_ptr, num_elements * sizeof(T)); - if (t_ptr == NULL) error("Out of memory. Cannot reallocate %i bytes", num_elements * sizeof(T)); + if (t_ptr == NULL) ReallocError(num_elements * sizeof(T)); return t_ptr; }