1 /* Copyright (c) 1997-1999 Miller Puckette.
2 * For information on usage and redistribution, and for a DISCLAIMER OF ALL
3 * WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
20 /* #define DEBUGMEM */
22 static int totalmem
= 0;
25 void *getbytes(size_t nbytes
)
28 if (nbytes
< 1) nbytes
= 1;
29 ret
= (void *)calloc(nbytes
, 1);
31 fprintf(stderr
, "new %x %d\n", (int)ret
, nbytes
);
37 post("pd: getbytes() failed -- out of memory");
41 void *getzbytes(size_t nbytes
) /* obsolete name */
43 return (getbytes(nbytes
));
46 void *copybytes(void *src
, size_t nbytes
)
49 ret
= getbytes(nbytes
);
51 memcpy(ret
, src
, nbytes
);
55 void *resizebytes(void *old
, size_t oldsize
, size_t newsize
)
58 if (newsize
< 1) newsize
= 1;
59 if (oldsize
< 1) oldsize
= 1;
60 ret
= (void *)realloc((char *)old
, newsize
);
61 if (newsize
> oldsize
&& ret
)
62 memset(((char *)ret
) + oldsize
, 0, newsize
- oldsize
);
64 fprintf(stderr
, "resize %x %d --> %x %d\n", (int)old
, oldsize
, (int)ret
, newsize
);
67 totalmem
+= (newsize
- oldsize
);
70 post("pd: resizebytes() failed -- out of memory");
74 void freebytes(void *fatso
, size_t nbytes
)
79 fprintf(stderr
, "free %x %d\n", (int)fatso
, nbytes
);
90 void glob_foo(void *dummy
, t_symbol
*s
, int argc
, t_atom
*argv
)
92 fprintf(stderr
, "total mem %d\n", totalmem
);