-
Notifications
You must be signed in to change notification settings - Fork 0
/
mem.h
34 lines (31 loc) · 991 Bytes
/
mem.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#ifndef MEM_INCLUDED
#define MEM_INCLUDED
#include "except.h"
#include <stdio.h>
extern void *Mem_alloc(long nbytes,
const char *file, int line);
extern const Except_T Mem_Failed;
#define ALLOC(nbytes) \
Mem_alloc((nbytes), __FILE__, __LINE__)
extern void *Mem_calloc(long count, long nbytes,
const char *file, int line);
#define CALLOC(count, nbytes) \
Mem_calloc(count, nbytes, __FILE__, __LINE__)
/*
* Using sizeof *p can adapt to any type.
* */
#define NEW(p) ((p) = ALLOC((long)sizeof *(p)))
#define NEW0(p) ((p) = CALLOC(1, (long)sizeof *(p)))
extern void Mem_free(void *ptr, const char *file, int line);
/*
* Free the ptr and set ptr = NULL
* Here uses the comma experssion.
* */
#define FREE(ptr) ((void)(Mem_free((ptr), \
__FILE__, __LINE__), (ptr) = 0))
extern void *Mem_resize(void *ptr, long nbytes,
const char *file, int line);
#define RESIZE(ptr, nbytes) ((ptr) = Mem_resize((ptr), \
(nbytes), __FILE__, __LINE__))
extern void printAF(FILE *);
#endif