aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/utils.c
diff options
context:
space:
mode:
authorZdenek Kabelac <kabi@informatics.muni.cz>2002-12-03 19:40:35 +0000
committerZdenek Kabelac <kabi@informatics.muni.cz>2002-12-03 19:40:35 +0000
commit855ea723b0ea450137e54674179751c14e8fc6b5 (patch)
treee8c81d27ce40b9c8f4f064cf06b464e26fed4d09 /libavcodec/utils.c
parent17308326396778cd31451ef7a69c36c7ccb7cab7 (diff)
downloadffmpeg-855ea723b0ea450137e54674179751c14e8fc6b5.tar.gz
* two functions to handle allocation of static data more simple
av_mallocz_static - called for every static data table av_free_static - called when ffmpeg is no longer needed and should free all static resources * simple usage shown in mpegaudiodec.c Originally committed as revision 1301 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/utils.c')
-rw-r--r--libavcodec/utils.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 6797508e1b..969507e5ea 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -30,6 +30,43 @@ void *av_mallocz(unsigned int size)
return ptr;
}
+/* allocation of static arrays - do not use for normal allocation */
+static unsigned int last_static = 0;
+static char*** array_static = NULL;
+static const unsigned int grow_static = 64; // ^2
+void *__av_mallocz_static(void** location, unsigned int size)
+{
+ int l = (last_static + grow_static) & ~(grow_static - 1);
+ void *ptr = av_mallocz(size);
+ if (!ptr)
+ return NULL;
+
+ if (location)
+ {
+ if (l > last_static)
+ array_static = realloc(array_static, l);
+ array_static[last_static++] = (char**) location;
+ *location = ptr;
+ }
+ return ptr;
+}
+/* free all static arrays and reset pointers to 0 */
+void av_free_static()
+{
+ if (array_static)
+ {
+ unsigned i;
+ for (i = 0; i < last_static; i++)
+ {
+ free(*array_static[i]);
+ *array_static[i] = NULL;
+ }
+ free(array_static);
+ array_static = 0;
+ }
+ last_static = 0;
+}
+
/* cannot call it directly because of 'void **' casting is not automatic */
void __av_freep(void **ptr)
{