diff -r 33db3feea2af -r 14be8ee6a268 src/core/alloc_func.hpp --- a/src/core/alloc_func.hpp Mon Feb 11 19:10:33 2008 +0000 +++ b/src/core/alloc_func.hpp Mon Feb 11 20:23:38 2008 +0000 @@ -6,6 +6,15 @@ #define ALLOC_FUNC_HPP /** + * Functions to exit badly with an error message. + * It has to be linked so the error messages are not + * duplicated in each object file making the final + * binary needlessly large. + */ +void MallocError(size_t size); +void ReallocError(size_t size); + +/** * Simplified allocation function that allocates the specified number of * elements of the given type. It also explicitly casts it to the requested * type. @@ -25,7 +34,7 @@ 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 @@ 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 @@ } 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; }