Mercurial > libavcodec.hg
comparison utils.c @ 3758:c3643ddcbaab libavcodec
move memory functions from avcodec to avutil
| author | lu_zero |
|---|---|
| date | Mon, 25 Sep 2006 15:23:40 +0000 |
| parents | 0882d618eb57 |
| children | c38b14835b62 |
comparison
equal
deleted
inserted
replaced
| 3757:271eca88821b | 3758:c3643ddcbaab |
|---|---|
| 55 0x0F,0x8F,0x4F,0xCF,0x2F,0xAF,0x6F,0xEF,0x1F,0x9F,0x5F,0xDF,0x3F,0xBF,0x7F,0xFF, | 55 0x0F,0x8F,0x4F,0xCF,0x2F,0xAF,0x6F,0xEF,0x1F,0x9F,0x5F,0xDF,0x3F,0xBF,0x7F,0xFF, |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 static int volatile entangled_thread_counter=0; | 58 static int volatile entangled_thread_counter=0; |
| 59 | 59 |
| 60 void *av_mallocz(unsigned int size) | |
| 61 { | |
| 62 void *ptr; | |
| 63 | |
| 64 ptr = av_malloc(size); | |
| 65 if (!ptr) | |
| 66 return NULL; | |
| 67 memset(ptr, 0, size); | |
| 68 return ptr; | |
| 69 } | |
| 70 | |
| 71 char *av_strdup(const char *s) | |
| 72 { | |
| 73 char *ptr; | |
| 74 int len; | |
| 75 len = strlen(s) + 1; | |
| 76 ptr = av_malloc(len); | |
| 77 if (!ptr) | |
| 78 return NULL; | |
| 79 memcpy(ptr, s, len); | |
| 80 return ptr; | |
| 81 } | |
| 82 | |
| 83 /** | 60 /** |
| 84 * realloc which does nothing if the block is large enough | 61 * realloc which does nothing if the block is large enough |
| 85 */ | 62 */ |
| 86 void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size) | 63 void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size) |
| 87 { | 64 { |
| 90 | 67 |
| 91 *size= FFMAX(17*min_size/16 + 32, min_size); | 68 *size= FFMAX(17*min_size/16 + 32, min_size); |
| 92 | 69 |
| 93 return av_realloc(ptr, *size); | 70 return av_realloc(ptr, *size); |
| 94 } | 71 } |
| 95 | |
| 96 | 72 |
| 97 static unsigned int last_static = 0; | 73 static unsigned int last_static = 0; |
| 98 static unsigned int allocated_static = 0; | 74 static unsigned int allocated_static = 0; |
| 99 static void** array_static = NULL; | 75 static void** array_static = NULL; |
| 100 | 76 |
| 155 static void do_free(void) | 131 static void do_free(void) |
| 156 { | 132 { |
| 157 av_free_static(); | 133 av_free_static(); |
| 158 } | 134 } |
| 159 | 135 |
| 160 /** | |
| 161 * Frees memory and sets the pointer to NULL. | |
| 162 * @param arg pointer to the pointer which should be freed | |
| 163 */ | |
| 164 void av_freep(void *arg) | |
| 165 { | |
| 166 void **ptr= (void**)arg; | |
| 167 av_free(*ptr); | |
| 168 *ptr = NULL; | |
| 169 } | |
| 170 | 136 |
| 171 /* encoder management */ | 137 /* encoder management */ |
| 172 AVCodec *first_avcodec = NULL; | 138 AVCodec *first_avcodec = NULL; |
| 173 | 139 |
| 174 void register_avcodec(AVCodec *format) | 140 void register_avcodec(AVCodec *format) |
