Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/memoryallocator.hpp

    • Property mode changed from 100644 to 100755
    rf66195 r7218f8  
    5555template <> char* Malloc<char>(size_t size, const char* output);
    5656
    57 /** Allocates a memory range using calloc().
     57/* Allocates a memory range using calloc().
    5858 * Prints the provided error message in case of a failure.
    5959 *
     
    6161 * \param failure message which is printed if the allocation fails
    6262 * \return pointer to the allocated memory range, will be NULL if a failure occurred
    63  */
     63*/
    6464template <typename X> X* Calloc(size_t size, const char* output)
    6565{
    6666  X* buffer = NULL;
    67   buffer = (X*) calloc(sizeof(X) * size, (size_t) 0);
     67  buffer = (X*) calloc(size, sizeof(X));
    6868
    6969  if (buffer != NULL) {
     
    7676  return buffer;
    7777};
     78
    7879
    7980/** Reallocates a memory range using realloc(). If the provided pointer to the old
     
    105106};
    106107
    107 /** Frees allocated memory range using free().
     108/** Frees allocated memory range using free(), NULL'ing \a **buffer.
    108109 *
    109  * \param pointer to the allocated memory range to free; may be NULL, this function is a no-op then
     110 * \param **buffer to the allocated memory range to free; may be NULL, this function is a no-op then
    110111 * \param *msg optional error message
    111112 */
     
    115116    return;
    116117
    117   MemoryUsageObserver::getInstance()->removeMemory(*buffer);
     118  MemoryUsageObserver::getInstance()->removeMemory(*buffer, msg);
    118119  free(*buffer);
    119120  *buffer = NULL;
    120121};
    121122
     123/** Frees allocated memory range using free() for ... * const \a buffer types.
     124 *
     125 * \param *buffer to the allocated memory range to free; may be NULL, this function is a no-op then
     126 * \param *msg optional error message
     127 */
     128template <typename X> void Free(X* const buffer, const char *msg = NULL)
     129{
     130  if ((buffer == NULL))
     131    return;
     132
     133  MemoryUsageObserver::getInstance()->removeMemory(buffer, msg);
     134  free(buffer);
     135};
     136
    122137#endif /*MEMORYALLOCATOR_HPP_*/
Note: See TracChangeset for help on using the changeset viewer.