summaryrefslogtreecommitdiff
path: root/retrace.hpp
diff options
context:
space:
mode:
authorJosé Fonseca <jose.r.fonseca@gmail.com>2012-03-30 20:41:25 +0100
committerJosé Fonseca <jose.r.fonseca@gmail.com>2012-03-30 20:41:25 +0100
commit12a22803faa06a0db229b6dfb6130a0e8156ba31 (patch)
tree84e9caf216a3c947e149e003cc452d85fd8f4ec6 /retrace.hpp
parentee659c84695e9f94b1f6a5f8be203dc0012ca685 (diff)
parent5409d1ebd76a55030be01c753722bdf9cb303995 (diff)
Merge branch 'master' into d3dretrace
Conflicts: retrace.py
Diffstat (limited to 'retrace.hpp')
-rw-r--r--retrace.hpp49
1 files changed, 48 insertions, 1 deletions
diff --git a/retrace.hpp b/retrace.hpp
index a4559c73..1b5fdd23 100644
--- a/retrace.hpp
+++ b/retrace.hpp
@@ -1,6 +1,6 @@
/**************************************************************************
*
- * Copyright 2011 Jose Fonseca
+ * Copyright 2011-2012 Jose Fonseca
* All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -84,6 +84,53 @@ public:
};
+/**
+ * Similar to alloca(), but implemented with malloc.
+ */
+class ScopedAllocator
+{
+private:
+ void *next;
+
+public:
+ ScopedAllocator() :
+ next(NULL) {
+ }
+
+ inline void *
+ alloc(size_t size) {
+ if (!size) {
+ return NULL;
+ }
+
+ void * * buf = static_cast<void **>(malloc(sizeof(void *) + size));
+ if (!buf) {
+ return NULL;
+ }
+
+ *buf = next;
+ next = buf;
+
+ return &buf[1];
+ }
+
+ template< class T >
+ inline T *
+ alloc(size_t n = 1) {
+ return static_cast<T *>(alloc(sizeof(T) * n));
+ }
+
+ inline
+ ~ScopedAllocator() {
+ while (next) {
+ void *temp = *static_cast<void **>(next);
+ free(next);
+ next = temp;
+ }
+ }
+};
+
+
void
addRegion(unsigned long long address, void *buffer, unsigned long long size);