Index: src/Helpers/MemDebug.cpp
===================================================================
--- src/Helpers/MemDebug.cpp	(revision 28c351085177bd0f8014422f461b534e27b03063)
+++ src/Helpers/MemDebug.cpp	(revision 2247a948dcf209ad31d8e876f040a37ae13d4500)
@@ -13,7 +13,20 @@
 
 namespace Memory {
+
+  // This struct is added before each memory chunk
+  // and contains tracking information. Anything used
+  // to track memory cannot use any dynamic memory, so
+  // we have to resort to classic C-idioms here.
+  // This struct also contains pointers to the next
+  // an previous chunks to allow fast traversion of
+  // all allocated memory blocks
   struct entry_t {
+    // we seperate the tracking info from the rest
+    // A checksum will be calculated for this part of
+    // the struct, so the information in here should
+    // not change during the lifetime of the memory
     struct info_t {
-      char file[256];
+      enum {length = 64};
+      char file[length+1];
       int line;
       size_t nbytes;
@@ -27,12 +40,23 @@
   };
 
+  // start and end of the doubly-linked list
   entry_t *begin=0;
   entry_t *end=0;
 
+  // current amount of allocated memory
   size_t state = 0;
+  // maximum amount of allocated memory
   size_t max = 0;
-
+  // number of allocations that have been done so far
+  unsigned int allocs = 0;
+
+
+  // this sets the alignment of the returned memory block
+  // malloc guarantees an alignment at the 8 byte border,
+  // so we just do the same
   const int alignment = 8;
 
+  // calculates a simple checksum for the info block
+  // the checksum is used to find memory corruptions
   inline char calcChecksum(entry_t::info_t *info){
     char *buffer = (char*)info;
@@ -44,4 +68,7 @@
   }
 
+  // gets the next alignet point which is greater than nbytes
+  // this function is only called a fixed number of times, so
+  // there is no need to optimize
   inline size_t doAlign(size_t nbytes){
     int nonaligned = nbytes % alignment;
@@ -54,8 +81,11 @@
   }
 
+  // Output some state information
   void getState(){
     cout << "Maximum allocated Memory: " << max << " bytes" << endl;
     cout << "Currently allocated Memory: " << state <<" bytes" << endl;
-
+    cout << allocs << " allocated chunks total" << endl;
+
+    // simple traversal of the chunk list
     for(entry_t *pos=begin;pos;pos=pos->next){
       cout << "\nChunk of " << pos->info.nbytes << " bytes" << " still available" << endl;
@@ -64,11 +94,14 @@
   }
 
+  // Deletes an entry from the linked list
   void deleteEntry(entry_t *entry){
     if(entry->isIgnored)
       return;
+
     if(entry->prev){
       entry->prev->next = entry->next;
     }
     else{
+      // this node was the beginning of the list
       begin = entry->next;
     }
@@ -78,4 +111,5 @@
     }
     else{
+      // this node was the end of the list
       end = entry->prev;
     }
@@ -85,4 +119,5 @@
 
   void _ignore(void *ptr){
+    // just deletes the node from the list, but leaves the info intact
     static const size_t entrySpace = Memory::doAlign(sizeof(Memory::entry_t));
     entry_t *entry = (Memory::entry_t*)((char*)ptr-entrySpace);
@@ -93,61 +128,86 @@
 void *operator new(size_t nbytes,const char* file, int line) throw(std::bad_alloc) {
 
+  // to avoid allocations of 0 bytes if someone screws up
+  // allocation with 0 byte size are undefined behavior, so we are
+  // free to handle it this way
   if(!nbytes) {
     nbytes = 1;
   }
 
+  // get the size of the entry, including alignment
   static const size_t entrySpace = Memory::doAlign(sizeof(Memory::entry_t));
 
   void *res;
   if(!(res=malloc(entrySpace + nbytes))){
+    // new must throw, when space is low
     throw std::bad_alloc();
   }
 
+  // we got the space, so update the global info
   Memory::state += nbytes;
   if(Memory::state>Memory::max){
     Memory::max = Memory::state;
   }
-
+  Memory::allocs++;
+
+  // build the entry in front of the space
   Memory::entry_t *entry = (Memory::entry_t*) res;
   entry->info.nbytes = nbytes;
   entry->info.isUsed = true;
-  strncpy(entry->info.file,file,256);
-  entry->info.file[255] = '\0';
+  strncpy(entry->info.file,file,Memory::entry_t::info_t::length);
+  entry->info.file[Memory::entry_t::info_t::length] = '\0';
   entry->info.line=line;
+  // the space starts behind the info
   entry->info.location = (char*)res + entrySpace;
 
-  entry->next=0;
-  entry->prev=Memory::end;
+  // add the entry at the end of the list
+  entry->next=0;            // the created block is last in the list
+  entry->prev=Memory::end;  // the created block is last in the list
   if(!Memory::begin){
+    // the list was empty... start a new one
     Memory::begin=entry;
   }
   else {
+    // other blocks present... we can add to the last one
     Memory::end->next=entry;
   }
   Memory::end=entry;
 
+  // get the checksum...
   entry->checksum = Memory::calcChecksum(&entry->info);
+  // this will be set to true, when the block is removed from
+  // the list for any reason
   entry->isIgnored = false;
 
+  // ok, space is prepared... the user can have it.
+  // the rest (constructor, deleting when something is thrown etc)
+  // is handled automatically
   return entry->info.location;
 }
 
 void *operator new(size_t nbytes) throw(std::bad_alloc) {
+  // Just forward to the other operator, when we do not know from
+  // where the allocation came
   return operator new(nbytes,"Unknown",0);
 }
 
 void *operator new[] (size_t nbytes,const char* file, int line) throw(std::bad_alloc) {
+  // The difference between new and new[] is just for compiler bookkeeping.
   return operator new(nbytes,file,line);
 }
 
 void *operator new[] (size_t nbytes) throw(std::bad_alloc) {
+  // Forward again
   return operator new[] (nbytes,"Unknown",0);
 }
 
 void operator delete(void *ptr) throw() {
+  // get the size for the entry, including alignment
   static const size_t entrySpace = Memory::doAlign(sizeof(Memory::entry_t));
 
+  // get the position for the entry from the pointer the user gave us
   Memory::entry_t *entry = (Memory::entry_t*)((char*)ptr-entrySpace);
 
+  // let's see if the checksum is still matching
   if(Memory::calcChecksum(&entry->info)!=entry->checksum){
     cout << "Possible memory corruption detected!" << endl;
@@ -157,10 +217,14 @@
   }
 
+  // this will destroy the checksum, so double deletes are caught
   entry->info.isUsed = false;
   Memory::deleteEntry(entry);
 
+  // delete the space reserved by malloc
   free((char*)ptr-entrySpace);
 }
 
+// operator that is called when the constructor throws
+// do not call manually
 void operator delete(void *ptr,const char*, int) throw() {
   operator delete(ptr);
@@ -168,7 +232,9 @@
 
 void operator delete[](void *ptr){
+  // again difference between delete and delete[] is just in compiler bookkeeping
   operator delete(ptr);
 }
 
+// and another operator that can be called when a constructor throws
 void operator delete[](void *ptr,const char*, int) throw(){
   operator delete(ptr);
Index: src/Helpers/MemDebug.hpp
===================================================================
--- src/Helpers/MemDebug.hpp	(revision 28c351085177bd0f8014422f461b534e27b03063)
+++ src/Helpers/MemDebug.hpp	(revision 2247a948dcf209ad31d8e876f040a37ae13d4500)
@@ -9,9 +9,33 @@
 #define MEMDEBUG_HPP_
 
+/**
+ * @file
+ * This module allows easy automatic memory tracking. Link this module to replace the
+ * operators new, new[], delete and delete[] with custom versions that add tracking
+ * information to allocated blocks.
+ *
+ * All tracking is done in O(1) for new and delete operators. Summaries for the
+ * used memory take O(N), where N is the number of currently allocated memory chunks.
+ *
+ * To use full tracking including file name and line number include this file in
+ * your sourcefiles.
+ */
+
 namespace Memory {
+
+  /**
+   * Displays a short summary of the memory state.
+   */
   void getState();
 
   void _ignore(void*);
 
+  /**
+   * Use this to disable memory for a certain pointer on the heap.
+   * This is useful for pointers which should live over the run of the
+   * program, and which are deleted automatically at the end. Usually these
+   * pointers should be wrapped inside some kind of smart pointer to
+   * ensure destruction at the end.
+   */
   template <typename T>
   T *ignore(T* ptr){
@@ -26,5 +50,8 @@
 void operator delete[] (void *ptr,const char*, int) throw();
 
-
+/**
+ * This macro replaces all occurences of the keyword new with a replaced
+ * version that allows tracking.
+ */
 #define new new(__FILE__,__LINE__)
 
Index: src/Helpers/fast_functions.hpp
===================================================================
--- src/Helpers/fast_functions.hpp	(revision 2247a948dcf209ad31d8e876f040a37ae13d4500)
+++ src/Helpers/fast_functions.hpp	(revision 2247a948dcf209ad31d8e876f040a37ae13d4500)
@@ -0,0 +1,82 @@
+/*
+ * fast_functions.hpp
+ *
+ *  Created on: Apr 1, 2010
+ *      Author: crueger
+ */
+
+#ifndef FAST_FUNCTIONS_HPP_
+#define FAST_FUNCTIONS_HPP_
+
+#include "defs.hpp"
+
+/**
+ * !@file
+ * This file contains several functions that need to be very fast and which are inlined for this
+ * reason.
+ *
+ * Warning: do not forget inline keyword for functions in this file to avoid multiple definitions!
+ */
+
+/********************************* Functions ************************************************/
+
+/** hard-coded determinant of a 3x3 matrix.
+ * \param a[9] matrix
+ * \return \f$det(a)\f$
+ */
+inline double RDET3(const double a[NDIM*NDIM])
+{
+  return ((a)[0]*(a)[4]*(a)[8] + (a)[3]*(a)[7]*(a)[2] + (a)[6]*(a)[1]*(a)[5] - (a)[2]*(a)[4]*(a)[6] - (a)[5]*(a)[7]*(a)[0] - (a)[8]*(a)[1]*(a)[3]);
+};
+
+/** hard-coded determinant of a 2x2 matrix.
+ * \param a[4] matrix
+ * \return \f$det(a)\f$
+ */
+inline double RDET2(const double a[4])
+{
+  return ((a[0])*(a[3])-(a[1])*(a[2]));
+};
+
+/** hard-coded determinant of a 2x2 matrix.
+ * \param a0 (0,0) entry of matrix
+ * \param a1 (0,1) entry of matrix
+ * \param a2 (1,0) entry of matrix
+ * \param a3 (1,1) entry of matrix
+ * \return \f$det(a)\f$
+ */
+inline double RDET2(const double a0, const double a1, const double a2, const double a3)
+{
+  return ((a0)*(a3)-(a1)*(a2));
+};
+
+/** Returns the power of \a n with respect to \a base.
+ * \param base basis
+ * \param n power
+ * \return \f$base^n\f$
+ */
+inline int pot(int base, int n)
+{
+  int res = 1;
+  int j;
+  for (j=n;j--;)
+    res *= base;
+  return res;
+};
+
+/*************************** Templatized functions ************************************/
+
+/** Flips two values.
+ * \param x first value
+ * \param y second value
+ */
+template <typename T>
+inline void flip(T &x, T &y)
+{
+  T tmp;
+  tmp = x;
+  x = y;
+  y = tmp;
+};
+
+#endif /* FAST_FUNCTIONS_HPP_ */
