From d884099e0db8b4510847ec106b59ef7dca3c245b Mon Sep 17 00:00:00 2001 From: Kenneth Heafield Date: Fri, 18 Jan 2013 17:12:51 +0000 Subject: KenLM dffafbf with lmplz source (but not built) --- klm/util/scoped.cc | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 klm/util/scoped.cc (limited to 'klm/util/scoped.cc') diff --git a/klm/util/scoped.cc b/klm/util/scoped.cc new file mode 100644 index 00000000..e7066ee4 --- /dev/null +++ b/klm/util/scoped.cc @@ -0,0 +1,29 @@ +#include "util/scoped.hh" + +#include + +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 -- cgit v1.2.3