Fix pdbox makefile to actually take part in dependency generation
[kugel-rb.git] / apps / plugins / pdbox / PDa / src / m_memory.c
blobd32aab3b7a96b3a8892a46ceb6f1779b24dc8193
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. */
5 #ifdef ROCKBOX
6 #include "plugin.h"
7 #include "../../pdbox.h"
8 #else /* ROCKBOX */
9 #include <stdlib.h>
10 #include <string.h>
11 #endif /* ROCKBOX */
12 #include "m_pd.h"
13 #include "m_imp.h"
15 /* #define LOUD */
16 #ifdef LOUD
17 #include <stdio.h>
18 #endif
20 /* #define DEBUGMEM */
21 #ifdef DEBUGMEM
22 static int totalmem = 0;
23 #endif
25 void *getbytes(size_t nbytes)
27 void *ret;
28 if (nbytes < 1) nbytes = 1;
29 ret = (void *)calloc(nbytes, 1);
30 #ifdef LOUD
31 fprintf(stderr, "new %x %d\n", (int)ret, nbytes);
32 #endif /* LOUD */
33 #ifdef DEBUGMEM
34 totalmem += nbytes;
35 #endif
36 if (!ret)
37 post("pd: getbytes() failed -- out of memory");
38 return (ret);
41 void *getzbytes(size_t nbytes) /* obsolete name */
43 return (getbytes(nbytes));
46 void *copybytes(void *src, size_t nbytes)
48 void *ret;
49 ret = getbytes(nbytes);
50 if (nbytes)
51 memcpy(ret, src, nbytes);
52 return (ret);
55 void *resizebytes(void *old, size_t oldsize, size_t newsize)
57 void *ret;
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);
63 #ifdef LOUD
64 fprintf(stderr, "resize %x %d --> %x %d\n", (int)old, oldsize, (int)ret, newsize);
65 #endif /* LOUD */
66 #ifdef DEBUGMEM
67 totalmem += (newsize - oldsize);
68 #endif
69 if (!ret)
70 post("pd: resizebytes() failed -- out of memory");
71 return (ret);
74 void freebytes(void *fatso, size_t nbytes)
76 if (nbytes == 0)
77 nbytes = 1;
78 #ifdef LOUD
79 fprintf(stderr, "free %x %d\n", (int)fatso, nbytes);
80 #endif /* LOUD */
81 #ifdef DEBUGMEM
82 totalmem -= nbytes;
83 #endif
84 free(fatso);
87 #ifdef DEBUGMEM
88 #include <stdio.h>
90 void glob_foo(void *dummy, t_symbol *s, int argc, t_atom *argv)
92 fprintf(stderr, "total mem %d\n", totalmem);
94 #endif