-
Notifications
You must be signed in to change notification settings - Fork 2
/
Alloc.c
122 lines (104 loc) · 3.32 KB
/
Alloc.c
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
* Alloc.c - memory allocation module
*
* DESCRIPTION
* This module contains routines that are used by the macros defined in
* "Alloc.h". None of these routines must be directly called by the user.
*
* INCLUDE FILES
* Alloc.h
*
* COPYRIGHT
* You are free to use, copy or modify this software at your own risk.
*
* AUTHOR
* Cornelis van der Bent. Please let me know if you have comments or find
* flaws: [email protected]. Enjoy!
*
* MODIFICATION HISTORY
* 1999/04/12 vdbent Thorough test and debugging; beta release.
* 1998/12/18 vdbent Conception.
*/
#include <stdlib.h>
#include "Except.h"
/******************************************************************************
*
* AllocCalloc - allocate a cleared chunk of memory
*
* DESCRIPTION
* This routine invokes the calloc() C library function for allocating
* a chunk of cleared memory.
*
* SIDE EFFECTS
* An EX_MEMORY exception is thrown when there's not enough memory.
*
* RETURNS
* Pointer to allocated memory.
*/
void * AllocCalloc(
Context * pC, /* pointer to thread exception context */
int number, /* number of elements */
int size, /* size of one element */
char * file, /* name of source file where invoked */
int line) /* source file line number */
{
void * pMem;
pMem = calloc(number, size);
if (pMem == NULL)
ExceptThrow(pC, OutOfMemoryError, NULL, file, line);
return pMem;
}
/******************************************************************************
*
* AllocMalloc - allocate chunk of memory
*
* DESCRIPTION
* This routine invokes the malloc() C library function for allocating
* a chunk of memory.
*
* SIDE EFFECTS
* An EX_MEMORY exception is thrown when there's not enough memory.
*
* RETURNS
* Pointer to allocated memory.
*/
void * AllocMalloc(
Context * pC, /* pointer to thread exception context */
int size, /* size of one element */
char * file, /* name of source file where invoked */
int line) /* source file line number */
{
void * pMem;
pMem = malloc(size);
if (pMem == NULL)
ExceptThrow(pC, OutOfMemoryError, NULL, file, line);
return pMem;
}
/******************************************************************************
*
* AllocRealloc - change size of allocated memory chunk
*
* DESCRIPTION
* This routine invokes the realloc() C library function for changing
* the size of <p>.
*
* SIDE EFFECTS
* An EX_MEMORY exception is thrown when there's not enough memory.
*
* RETURNS
* Pointer to allocated memory.
*/
void * AllocRealloc(
Context * pC, /* pointer to thread exception context */
void * p, /* pointer to original block */
int size, /* size of one element */
char * file, /* name of source file where invoked */
int line) /* source file line number */
{
void * pMem;
pMem = realloc(p, size);
if (pMem == NULL)
ExceptThrow(pC, OutOfMemoryError, NULL, file, line);
return pMem;
}
/* end of Alloc.c */