#ifndef _VISBD_MEMALLOC_H
#define _VISBD_MEMALLOC_H

template<typename T>
int  get_mem1D(T** array1D,int rows)
{
	if((*array1D = (T*)calloc(rows,       sizeof(T))) == NULL)
	{
		printf("no_mem_exit");
		exit(0);
	}

	return (sizeof(T*) + rows * sizeof(T));
}

template<typename T>
int get_mem2D(T*** array2D, int rows,int columns)
{
	int i=0;

	if((*array2D    = (T**)malloc(rows * sizeof(T*))) == NULL)
	{
		printf("no_mem_exit");
		exit(0);
	}
	if((*(*array2D) = (T* )calloc(rows * columns,sizeof(T))) == NULL)
	{
		printf("no_mem_exit");
		exit(0);
	}

	for(i = 1 ; i < rows; i++)
		(*array2D)[i] = (*array2D)[i-1] + columns;

	return rows * (sizeof(T*) + columns * sizeof(T));
}
template<typename T>
void free_mem1D(T* array1D)
{
	if (array1D)
	{
		free (array1D);
	}
}
template<typename T>
void free_mem2D(T**array2D)
{
	if (array2D)
	{
		if (*array2D)
			free (*array2D);
		free (array2D);
	} 
}
#endif

