Welcome to mirror list, hosted at ThFree Co, Russian Federation.

memory.cc « vowpalwabbit - github.com/moses-smt/vowpal_wabbit.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: aa3772d3fbfba1a02fb630774a32bb6f8a8053c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <stdlib.h>
#include <iostream>

void* calloc_or_die(size_t nmemb, size_t size)
{
  if (nmemb == 0 || size == 0)
    return NULL;
  
  void* data = calloc(nmemb, size);
  if (data == NULL) {
    std::cerr << "internal error: memory allocation failed; dying!" << std::endl;
    throw std::exception();
  }
  return data;
}

void free_it(void*ptr)
{
  if (ptr != NULL)
    free(ptr);
}