Wednesday, May 30, 2007

VC simple mem leak detection code

Add these lines into header:
#define _CRTDBG_MAP_ALLOC
#include <stdlib.h>
#include <crtdbg.h>
Call this function @ entry point
_CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );

Making std::pair work as the key of hash_map in VC

Simple hack:
namespace stdext
{
  template<typename T1, typename T2> inline size_t hash_value(const std::pair<T1, T2>& _Keyval)
  {
    return hash_value(_Keyval.first) * 196613 + hash_value(_Keyval.second);
  }
}