Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
241818 views
1
#include <stdlib.h>
2
#include <stdio.h>
3
#include <memory.h>
4
#include "gmp.h"
5
#include "cstd.h"
6
7
/*
8
Copyright 2007 Andrew V. Sutherland
9
10
This file is part of smalljac.
11
12
smalljac is free software: you can redistribute it and/or modify
13
it under the terms of the GNU General Public License as published by
14
the Free Software Foundation, either version 2 of the License, or
15
(at your option) any later version.
16
17
smalljac is distributed in the hope that it will be useful,
18
but WITHOUT ANY WARRANTY; without even the implied warranty of
19
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
GNU General Public License for more details.
21
22
You should have received a copy of the GNU General Public License
23
along with smalljac. If not, see <http://www.gnu.org/licenses/>.
24
*/
25
26
unsigned long mem_count;
27
unsigned long mem_bytes;
28
29
void *mem_alloc (unsigned long bytes)
30
{
31
void *ptr;
32
33
if ( bytes < 4 ) { err_printf ("mem_alloc to small - ptr error?!\n"); exit (0); }
34
if ( bytes == 4 ) { dbg_printf ("malloc 4 warning\n"); }
35
ptr = malloc (bytes);
36
if ( ! ptr ) { err_printf ("Fatal error, attempted memory allocation of %d bytes failed.\n"); exit (0); }
37
dbg_printf ("Allocated %lu bytes at %x\n", bytes, ptr);
38
memset (ptr, 0, bytes);
39
mem_count++;
40
mem_bytes += bytes;
41
return ptr;
42
}
43
44
void mem_free (void *ptr)
45
{ dbg_printf ("freed %x\n", ptr); free (ptr); }
46
47