summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2011-11-16 19:50:16 -0800
committerPixel <pixel@nobis-crew.org>2011-11-16 19:50:16 -0800
commit7c382a3cc4f4f399ace7f70e08629723aff111a1 (patch)
tree969c2a4c82b59a0df51882b3bbcd361adeba8922
parent18beadfdfb761e6a54be6093e65b66a431bacc19 (diff)
I hate doing this, but, well. Maybe I should design a memory allocator class, but, meh.
-rw-r--r--includes/Exceptions.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/includes/Exceptions.h b/includes/Exceptions.h
index e17e468..0563090 100644
--- a/includes/Exceptions.h
+++ b/includes/Exceptions.h
@@ -21,6 +21,33 @@ class GeneralException {
char * m_msg;
};
+static inline void * malloc(size_t size) throw (GeneralException) {
+ void * r = ::malloc(size);
+
+ if (!r && size)
+ throw GeneralException("Failed to allocate memory.");
+
+ return r;
+}
+
+static inline void * calloc(size_t count, size_t size) throw (GeneralException) {
+ void * r = ::calloc(count, size);
+
+ if (!r && ((count * size) != 0))
+ throw GeneralException("Failed to allocate memory.");
+
+ return r;
+}
+
+static inline void * realloc(void * previous, size_t size) throw (GeneralException) {
+ void * r = ::realloc(previous, size);
+
+ if (!r && size)
+ throw GeneralException("Failed to allocate memory.");
+
+ return r;
+}
+
static inline void AssertHelper(const String & msg) throw(GeneralException) { throw GeneralException(msg); }
class ClassName {