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:
Diffstat (limited to 'util/scoped.cc')
-rw-r--r--util/scoped.cc12
1 files changed, 8 insertions, 4 deletions
diff --git a/util/scoped.cc b/util/scoped.cc
index de1d9e940..84f4344b7 100644
--- a/util/scoped.cc
+++ b/util/scoped.cc
@@ -7,6 +7,8 @@
namespace util {
+// TODO: if we're really under memory pressure, don't allocate memory to
+// display the error.
MallocException::MallocException(std::size_t requested) throw() {
*this << "for " << requested << " bytes ";
}
@@ -16,10 +18,6 @@ MallocException::~MallocException() throw() {}
namespace {
void *InspectAddr(void *addr, std::size_t requested, const char *func_name) {
UTIL_THROW_IF_ARG(!addr && requested, MallocException, (requested), "in " << func_name);
- // These routines are often used for large chunks of memory where huge pages help.
-#if MADV_HUGEPAGE
- madvise(addr, requested, MADV_HUGEPAGE);
-#endif
return addr;
}
} // namespace
@@ -36,4 +34,10 @@ void scoped_malloc::call_realloc(std::size_t requested) {
p_ = InspectAddr(std::realloc(p_, requested), requested, "realloc");
}
+void AdviseHugePages(const void *addr, std::size_t size) {
+#if MADV_HUGEPAGE
+ madvise((void*)addr, size, MADV_HUGEPAGE);
+#endif
+}
+
} // namespace util