summaryrefslogtreecommitdiff
path: root/klm/util/scoped.hh
diff options
context:
space:
mode:
authorKenneth Heafield <github@kheafield.com>2013-01-18 17:12:51 +0000
committerKenneth Heafield <github@kheafield.com>2013-01-18 17:12:51 +0000
commit0b9031042500d45a098762f0a930bd6a66a58fac (patch)
tree38903f3e29225aa8d444ee66b6963c7148050fee /klm/util/scoped.hh
parent9d7167751a3712a79ad356764d803106a71ce5e3 (diff)
KenLM dffafbf with lmplz source (but not built)
Diffstat (limited to 'klm/util/scoped.hh')
-rw-r--r--klm/util/scoped.hh17
1 files changed, 10 insertions, 7 deletions
diff --git a/klm/util/scoped.hh b/klm/util/scoped.hh
index d62c6df1..d0a5aabd 100644
--- a/klm/util/scoped.hh
+++ b/klm/util/scoped.hh
@@ -4,28 +4,31 @@
#include "util/exception.hh"
#include <cstddef>
-#include <cstdlib>
namespace util {
+class MallocException : public ErrnoException {
+ public:
+ explicit MallocException(std::size_t requested) throw();
+ ~MallocException() throw();
+};
+
+void *MallocOrThrow(std::size_t requested);
+
class scoped_malloc {
public:
scoped_malloc() : p_(NULL) {}
scoped_malloc(void *p) : p_(p) {}
- ~scoped_malloc() { std::free(p_); }
+ ~scoped_malloc();
void reset(void *p = NULL) {
scoped_malloc other(p_);
p_ = p;
}
- void call_realloc(std::size_t to) {
- void *ret;
- UTIL_THROW_IF(!(ret = std::realloc(p_, to)) && to, util::ErrnoException, "realloc to " << to << " bytes failed.");
- p_ = ret;
- }
+ void call_realloc(std::size_t to);
void *get() { return p_; }
const void *get() const { return p_; }