#include <stdlib.h>1#include <stdio.h>2#include <memory.h>3#include "gmp.h"4#include "cstd.h"56/*7Copyright 2007 Andrew V. Sutherland89This file is part of smalljac.1011smalljac is free software: you can redistribute it and/or modify12it under the terms of the GNU General Public License as published by13the Free Software Foundation, either version 2 of the License, or14(at your option) any later version.1516smalljac is distributed in the hope that it will be useful,17but WITHOUT ANY WARRANTY; without even the implied warranty of18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the19GNU General Public License for more details.2021You should have received a copy of the GNU General Public License22along with smalljac. If not, see <http://www.gnu.org/licenses/>.23*/2425unsigned long mem_count;26unsigned long mem_bytes;2728void *mem_alloc (unsigned long bytes)29{30void *ptr;3132if ( bytes < 4 ) { err_printf ("mem_alloc to small - ptr error?!\n"); exit (0); }33if ( bytes == 4 ) { dbg_printf ("malloc 4 warning\n"); }34ptr = malloc (bytes);35if ( ! ptr ) { err_printf ("Fatal error, attempted memory allocation of %d bytes failed.\n"); exit (0); }36dbg_printf ("Allocated %lu bytes at %x\n", bytes, ptr);37memset (ptr, 0, bytes);38mem_count++;39mem_bytes += bytes;40return ptr;41}4243void mem_free (void *ptr)44{ dbg_printf ("freed %x\n", ptr); free (ptr); }454647