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

github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenneth Heafield <github@kheafield.com>2013-01-18 19:58:54 +0400
committerKenneth Heafield <github@kheafield.com>2013-01-18 19:59:51 +0400
commitfc5868d0fff647c3879668af4bfe6e1bab9e83ab (patch)
treed9b5026f32cc5ae603e6f42b1fc7128aeee4ba55 /util/scoped.cc
parent5f7b91e702f809577d82a7570778d254d985ba93 (diff)
KenLM df5be22 lmplz for estimation
Diffstat (limited to 'util/scoped.cc')
-rw-r--r--util/scoped.cc29
1 files changed, 29 insertions, 0 deletions
diff --git a/util/scoped.cc b/util/scoped.cc
new file mode 100644
index 000000000..e7066ee47
--- /dev/null
+++ b/util/scoped.cc
@@ -0,0 +1,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