/*
* $Log: $
* $Locker:  $
 */
#ifndef MALLOC_DBG_H
#define MALLOC_DBG_H

#include <stdio.h>

extern size_t md_allocated;
extern size_t md_peek;

static void *md_malloc(size_t size)
{
   size_t add = sizeof(size_t);
   size_t s2 = size+add;
   void *p = malloc(s2);
   *(size_t *)p  = size;
   md_allocated += size;
   if( md_allocated > md_peek )
      md_peek = md_allocated;
   return ((char *)p)+add;
}

static void md_free(void *p)
{
   size_t add = sizeof(size_t);
   p = (((char *)p)-add);
   if( *(size_t *)p  == 1000000000 )
      fprintf(stderr,"ERROR");
   md_allocated -= *(size_t *)(p);
   *(size_t *)p = 1000000000;
   free(p);
}


static void md_stat()
{
   printf("%ld/%ld bytes allocated\n",md_allocated,md_peek);
}

#define malloc md_malloc
#define free md_free
#define MD_STAT 1


#endif
