// stdafx.cpp : source file that includes just the standard includes
// QRGenerator.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information

#include "stdafx.h"
#include "stdlib.h"

/*
void * __cdecl m_malloc(_In_ size_t _Size)
{
  static int sum=0;
  sum+=_Size;
  printf("SUM=%8u (%u)\n",(int)sum,(int)(_Size)); return(malloc(_Size));
}

void __cdecl m_free(void *p)
{
  free(p);
}
*/

int velikost_pameti;
int pamet_max;

#define DELKA_POLE 1000
void * g_p[DELKA_POLE] = {0};
size_t g_size[DELKA_POLE] = {0};

// void * __cdecl m_malloc(_In_ size_t _Size)
void * m_malloc(size_t _Size)
{
  static int sum=0;
  sum+=_Size;
  printf("SUM=%8u (%u)\n",(int)sum,(int)(_Size));
  printf("MAX=%8u\n",(int)pamet_max);
  
  void * p;
  p = malloc(_Size);
  
  for(int i = 0; i < DELKA_POLE; i++ )
  {
    if(g_p[i]) continue;
    g_p[i] = p;
    g_size[i] = _Size;
	  break;
  }
  velikost_pameti = velikost_pameti + (_Size);				//pocitani pameti

  if (velikost_pameti > pamet_max)
  {
    pamet_max = velikost_pameti;
  }
  return (p);
}

void __cdecl m_free(void *p)
{
  for(int i = 0; i < DELKA_POLE; i++ )
  {
    if(p==0)
      break;
    if(p!=g_p[i]) continue;
    g_p[i] = 0;
    velikost_pameti -= g_size[i];
	  break;
  }
  free(p);
}



// TODO: reference any additional headers you need in STDAFX.H
// and not in this file
