Blame | Last modification | View Log | RSS feed
/*CPP V5 -- Memory management routines.source: mem.cstarted: September 20, 1985version: October 15, 1987; March 24, 1988Written by Edward K. Ream.This software is in the public domain.See the read.me file for disclaimer and other information.*/#include "cpp.h"#if defined(MICRO_SOFT) || defined(__WATCOMC__)#include <malloc.h>#else#include <alloc.h>#endif/* Define local data structures. */static long m_tot = 0; /* Total number of bytes allocated. *//*Allocate n bytes using calloc(), assumed to get memory from systemThe returned memory IS zeroed.*/void *m_alloc(n)int n;{register char *p;TRACEP("m_alloc", printf("(%d): ", n));/* Align the request. */while (n & (sizeof(short int)-1) ) {n++;}p = calloc(1, (unsigned) n);if (p == NULL) {printf("sorry, out of memory\n");m_stat();exit(BAD_EXIT);}/* Update statistics. */m_tot += (long) n;TRACEN("m_alloc", printf("returns %p\n", p));return p;}/*Free memory allocated by m_alloc().*/voidm_free(p)void *p;{TRACEP("m_free", printf("(%p)\n", p));if (p == NULL) {syserr("m_free: trying to free a NULL pointer.");}else {free(p);}}/*Print statistics about memory manager.*/voidm_stat(){TRACEP("m_stat", printf("m_tot: %ld (0x%lx)\n", m_tot, m_tot));}