summaryrefslogtreecommitdiff
path: root/apps/plugins/pdbox/PDa/src/m_memory.c
diff options
context:
space:
mode:
authorPeter D'Hoye <peter.dhoye@gmail.com>2009-05-22 21:58:48 +0000
committerPeter D'Hoye <peter.dhoye@gmail.com>2009-05-22 21:58:48 +0000
commit513389b4c1bc8afe4b2dc9947c534bfeb105e3da (patch)
tree10e673b35651ac567fed2eda0c679c7ade64cbc6 /apps/plugins/pdbox/PDa/src/m_memory.c
parent95fa7f6a2ef466444fbe3fe87efc6d5db6b77b36 (diff)
downloadrockbox-513389b4c1bc8afe4b2dc9947c534bfeb105e3da.zip
rockbox-513389b4c1bc8afe4b2dc9947c534bfeb105e3da.tar.gz
rockbox-513389b4c1bc8afe4b2dc9947c534bfeb105e3da.tar.bz2
rockbox-513389b4c1bc8afe4b2dc9947c534bfeb105e3da.tar.xz
Add FS #10214. Initial commit of the original PDa code for the GSoC Pure Data plugin project of Wincent Balin. Stripped some non-sourcefiles and added a rockbox readme that needs a bit more info from Wincent. Is added to CATEGORIES and viewers, but not yet to SUBDIRS (ie doesn't build yet)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21044 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/pdbox/PDa/src/m_memory.c')
-rw-r--r--apps/plugins/pdbox/PDa/src/m_memory.c178
1 files changed, 178 insertions, 0 deletions
diff --git a/apps/plugins/pdbox/PDa/src/m_memory.c b/apps/plugins/pdbox/PDa/src/m_memory.c
new file mode 100644
index 0000000..0851542
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/src/m_memory.c
@@ -0,0 +1,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