home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
vol_300
/
355_02
/
slk2.exe
/
SPP
/
MEM.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-06-09
|
2KB
|
99 lines
/*
Sherlock Preprocessor -- Memory management routines.
source: mem.c
started: September 20, 1985
version: March 29, 1988; July 2, 1988
PUBLIC DOMAIN SOFTWARE
Sherlock, including the SPP, SDEL and SDIF programs, was placed in
the public domain on June 15, 1991, by its author,
Edward K. Ream
166 North Prospect Ave.
Madison, WI 53705.
(608) 257-0802
Sherlock may be used for any commercial or non-commercial purpose.
DISCLAIMER OF WARRANTIES
Edward K. Ream (Ream) specifically disclaims all warranties,
expressed or implied, with respect to this computer software,
including but not limited to implied warranties of merchantability
and fitness for a particular purpose. In no event shall Ream be
liable for any loss of profit or any commercial damage, including
but not limited to special, incidental consequential or other damages.
*/
#include "spp.h"
#ifdef TURBOC
#include <alloc.h>
#else
#include <malloc.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 system
The returned memory IS zeroed.
*/
void *
m_alloc(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().
*/
void
m_free(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.
*/
void
m_stat(void)
{
TRACEP("m_stat",
printf("m_tot: %ld (0x%lx)\n", m_tot, m_tot));
}