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

scoped.cc « util - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e7066ee47ea9771a2e9cfe4701b66034642315d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "util/scoped.hh"

#include <cstdlib>

namespace util {

MallocException::MallocException(std::size_t requested) throw() {
  *this << "for " << requested << " bytes ";
}

MallocException::~MallocException() throw() {}

void *MallocOrThrow(std::size_t requested) {
  void *ret;
  UTIL_THROW_IF_ARG(!(ret = std::malloc(requested)), MallocException, (requested), "in malloc");
  return ret;
}

scoped_malloc::~scoped_malloc() {
  std::free(p_);
}

void scoped_malloc::call_realloc(std::size_t to) {
  void *ret;
  UTIL_THROW_IF_ARG(!(ret = std::realloc(p_, to)) && to, MallocException, (to), "in realloc");
  p_ = ret;
}

} // namespace util