Mercurial > libavcodec.hg
comparison utils.c @ 902:6acc8394960d libavcodec
* 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
author | kabi |
---|---|
date | Tue, 03 Dec 2002 19:40:35 +0000 |
parents | 058194d7ade6 |
children | 22ee74da2cd3 |
comparison
equal
deleted
inserted
replaced
901:07a677389920 | 902:6acc8394960d |
---|---|
28 return NULL; | 28 return NULL; |
29 memset(ptr, 0, size); | 29 memset(ptr, 0, size); |
30 return ptr; | 30 return ptr; |
31 } | 31 } |
32 | 32 |
33 /* allocation of static arrays - do not use for normal allocation */ | |
34 static unsigned int last_static = 0; | |
35 static char*** array_static = NULL; | |
36 static const unsigned int grow_static = 64; // ^2 | |
37 void *__av_mallocz_static(void** location, unsigned int size) | |
38 { | |
39 int l = (last_static + grow_static) & ~(grow_static - 1); | |
40 void *ptr = av_mallocz(size); | |
41 if (!ptr) | |
42 return NULL; | |
43 | |
44 if (location) | |
45 { | |
46 if (l > last_static) | |
47 array_static = realloc(array_static, l); | |
48 array_static[last_static++] = (char**) location; | |
49 *location = ptr; | |
50 } | |
51 return ptr; | |
52 } | |
53 /* free all static arrays and reset pointers to 0 */ | |
54 void av_free_static() | |
55 { | |
56 if (array_static) | |
57 { | |
58 unsigned i; | |
59 for (i = 0; i < last_static; i++) | |
60 { | |
61 free(*array_static[i]); | |
62 *array_static[i] = NULL; | |
63 } | |
64 free(array_static); | |
65 array_static = 0; | |
66 } | |
67 last_static = 0; | |
68 } | |
69 | |
33 /* cannot call it directly because of 'void **' casting is not automatic */ | 70 /* cannot call it directly because of 'void **' casting is not automatic */ |
34 void __av_freep(void **ptr) | 71 void __av_freep(void **ptr) |
35 { | 72 { |
36 av_free(*ptr); | 73 av_free(*ptr); |
37 *ptr = NULL; | 74 *ptr = NULL; |