/* * memoryallocator.cpp * * Created on: May 31, 2010 * Author: heber */ #include "Helpers/MemDebug.hpp" using namespace std; #include "memoryallocator.hpp" /** Allocates a memory range using malloc(). * Prints the provided error message in case of a failure. * * \param number of memory slices of type X to allocate * \param failure message which is printed if the allocation fails * \return pointer to the allocated memory range, will be NULL if a failure occurred */ template <> char* Malloc(size_t size, const char* output) { char* buffer = NULL; buffer = (char*) malloc(sizeof(char) * (size + 1)); for (size_t i = size; i--;) buffer[i] = (i % 2 == 0) ? 'p': 'c'; buffer[size] = '\0'; if (buffer != NULL) { //MemoryUsageObserver::getInstance()->addMemory(buffer, size); } else { Log() << Verbose(0) << "Malloc for datatype " << typeid(char).name() << " failed - pointer is NULL: " << output << endl; } return buffer; };