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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
/* Copyright (c) 1997-1999 Miller Puckette.
* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
#include <stdlib.h>
#include <string.h>
#include "m_pd.h"
#include "m_imp.h"
/* #define LOUD */
#ifdef LOUD
#include <stdio.h>
#endif
/* #define DEBUGMEM */
#ifdef DEBUGMEM
static int totalmem = 0;
#endif
void *getbytes(size_t nbytes)
{
void *ret;
if (nbytes < 1) nbytes = 1;
ret = (void *)calloc(nbytes, 1);
#ifdef LOUD
fprintf(stderr, "new %x %d\n", (int)ret, nbytes);
#endif /* LOUD */
#ifdef DEBUGMEM
totalmem += nbytes;
#endif
if (!ret)
post("pd: getbytes() failed -- out of memory");
return (ret);
}
void *getzbytes(size_t nbytes) /* obsolete name */
{
return (getbytes(nbytes));
}
void *copybytes(void *src, size_t nbytes)
{
void *ret;
ret = getbytes(nbytes);
if (nbytes)
memcpy(ret, src, nbytes);
return (ret);
}
void *resizebytes(void *old, size_t oldsize, size_t newsize)
{
void *ret;
if (newsize < 1) newsize = 1;
if (oldsize < 1) oldsize = 1;
ret = (void *)realloc((char *)old, newsize);
if (newsize > oldsize && ret)
memset(((char *)ret) + oldsize, 0, newsize - oldsize);
#ifdef LOUD
fprintf(stderr, "resize %x %d --> %x %d\n", (int)old, oldsize, (int)ret, newsize);
#endif /* LOUD */
#ifdef DEBUGMEM
totalmem += (newsize - oldsize);
#endif
if (!ret)
post("pd: resizebytes() failed -- out of memory");
return (ret);
}
void freebytes(void *fatso, size_t nbytes)
{
if (nbytes == 0)
nbytes = 1;
#ifdef LOUD
fprintf(stderr, "free %x %d\n", (int)fatso, nbytes);
#endif /* LOUD */
#ifdef DEBUGMEM
totalmem -= nbytes;
#endif
free(fatso);
}
#ifdef DEBUGMEM
#include <stdio.h>
void glob_foo(void *dummy, t_symbol *s, int argc, t_atom *argv)
{
fprintf(stderr, "total mem %d\n", totalmem);
}
#endif
/* Copyright (c) 1997-1999 Miller Puckette.
* For information on usage and redistribution, and for a DISCLAIMER OF ALL
* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
#include <stdlib.h>
#include <string.h>
#include "m_pd.h"
#include "m_imp.h"
/* #define LOUD */
#ifdef LOUD
#include <stdio.h>
#endif
/* #define DEBUGMEM */
#ifdef DEBUGMEM
static int totalmem = 0;
#endif
void *getbytes(size_t nbytes)
{
void *ret;
if (nbytes < 1) nbytes = 1;
ret = (void *)calloc(nbytes, 1);
#ifdef LOUD
fprintf(stderr, "new %x %d\n", (int)ret, nbytes);
#endif /* LOUD */
#ifdef DEBUGMEM
totalmem += nbytes;
#endif
if (!ret)
post("pd: getbytes() failed -- out of memory");
return (ret);
}
void *getzbytes(size_t nbytes) /* obsolete name */
{
return (getbytes(nbytes));
}
void *copybytes(void *src, size_t nbytes)
{
void *ret;
ret = getbytes(nbytes);
if (nbytes)
memcpy(ret, src, nbytes);
return (ret);
}
void *resizebytes(void *old, size_t oldsize, size_t newsize)
{
void *ret;
if (newsize < 1) newsize = 1;
if (oldsize < 1) oldsize = 1;
ret = (void *)realloc((char *)old, newsize);
if (newsize > oldsize && ret)
memset(((char *)ret) + oldsize, 0, newsize - oldsize);
#ifdef LOUD
fprintf(stderr, "resize %x %d --> %x %d\n", (int)old, oldsize, (int)ret, newsize);
#endif /* LOUD */
#ifdef DEBUGMEM
totalmem += (newsize - oldsize);
#endif
if (!ret)
post("pd: resizebytes() failed -- out of memory");
return (ret);
}
void freebytes(void *fatso, size_t nbytes)
{
if (nbytes == 0)
nbytes = 1;
#ifdef LOUD
fprintf(stderr, "free %x %d\n", (int)fatso, nbytes);
#endif /* LOUD */
#ifdef DEBUGMEM
totalmem -= nbytes;
#endif
free(fatso);
}
#ifdef DEBUGMEM
#include <stdio.h>
void glob_foo(void *dummy, t_symbol *s, int argc, t_atom *argv)
{
fprintf(stderr, "total mem %d\n", totalmem);
}
#endif
|