* src/mm/dumpmemory.hpp (DumpClass): Added new base class for dump memory.
authorMichael Starzinger <michi@complang.tuwien.ac.at>
Mon, 31 Aug 2009 13:22:31 +0000 (15:22 +0200)
committerMichael Starzinger <michi@complang.tuwien.ac.at>
Mon, 31 Aug 2009 13:22:31 +0000 (15:22 +0200)
* src/toolbox/list.hpp (DumpList): Uses above class to be allocated on dump
memory.

src/mm/dumpmemory.hpp
src/toolbox/list.hpp

index 79433a1864386310058d7d71810e1f1fb5893ce5..ff53ad42af885b75bab7884506ec08814c05e325 100644 (file)
@@ -49,6 +49,17 @@ class DumpMemoryAllocation;
 #endif
 
 
+/**
+ * All classes intended to be allocated on dump memory should extend this
+ * base class to inherit the appropriate allocation operators.
+ */
+class DumpClass {
+public:
+       void* operator new(size_t size);
+       void operator delete(void* p);
+};
+
+
 /**
  * Thread-local dump memory structure.
  */
@@ -222,6 +233,16 @@ public:
 
 // Inline functions.
 
+inline void* DumpClass::operator new(size_t size)
+{
+       return DumpMemory::allocate(size);
+}
+
+inline void DumpClass::operator delete(void* p)
+{
+       // We don't need to deallocate on dump memory.
+}
+
 inline DumpMemory* DumpMemory::get_current()
 {
        // Get the DumpMemory object of the current thread.
index 1509f1ba00e59be41da99eac33bef34710c0a2c1..53395be00ade144114205c63db0996e81018fdcc 100644 (file)
@@ -85,7 +85,9 @@ public:
 /**
  * List implementation with dump memory.
  */
-template<class T> class DumpList : protected std::list<T, DumpMemoryAllocator<T> > {
+template<class T> class DumpList :
+               public DumpClass,
+               protected std::list<T, DumpMemoryAllocator<T> > {
 public:
        virtual ~DumpList() {}
 
@@ -106,12 +108,6 @@ public:
        using std::list<T, DumpMemoryAllocator<T> >::remove;
        using std::list<T, DumpMemoryAllocator<T> >::rend;
        using std::list<T, DumpMemoryAllocator<T> >::size;
-
-       void* operator new(size_t size) {
-               return DumpMemory::allocate(size);
-       }
-
-       void operator delete(void* p) {}
 };
 
 #else
@@ -136,4 +132,5 @@ typedef struct DumpList DumpList;
  * c-basic-offset: 4
  * tab-width: 4
  * End:
+ * vim:noexpandtab:sw=4:ts=4:
  */