Mercurial > libavcodec.hg
comparison utils.c @ 1901:bc5039adb9af libavcodec
1000l in av_mallocz_static()
less overallocation in av_fast_realloc() for small arrays
author | michael |
---|---|
date | Mon, 22 Mar 2004 11:00:51 +0000 |
parents | 5cde80c5d929 |
children | 8d3540dddd1b |
comparison
equal
deleted
inserted
replaced
1900:5cde80c5d929 | 1901:bc5039adb9af |
---|---|
58 void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size) | 58 void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size) |
59 { | 59 { |
60 if(min_size < *size) | 60 if(min_size < *size) |
61 return ptr; | 61 return ptr; |
62 | 62 |
63 *size= min_size + 10*1024; | 63 *size= 17*min_size/16 + 32; |
64 | 64 |
65 return av_realloc(ptr, *size); | 65 return av_realloc(ptr, *size); |
66 } | 66 } |
67 | 67 |
68 | 68 |
69 static unsigned int last_static = 0; | 69 static unsigned int last_static = 0; |
70 static unsigned int allocated_static = 0; | 70 static unsigned int allocated_static = 0; |
71 static void** array_static = NULL; | 71 static void** array_static = NULL; |
72 static const unsigned int grow_static = 64; // ^2 | |
73 | 72 |
74 /** | 73 /** |
75 * allocation of static arrays - do not use for normal allocation. | 74 * allocation of static arrays - do not use for normal allocation. |
76 */ | 75 */ |
77 void *av_mallocz_static(unsigned int size) | 76 void *av_mallocz_static(unsigned int size) |
78 { | 77 { |
79 void *ptr = av_mallocz(size); | 78 void *ptr = av_mallocz(size); |
80 | 79 |
81 if(ptr){ | 80 if(ptr){ |
82 array_static =av_fast_realloc(array_static, &allocated_static, last_static+1); | 81 array_static =av_fast_realloc(array_static, &allocated_static, sizeof(void*)*(last_static+1)); |
83 array_static[last_static++] = ptr; | 82 array_static[last_static++] = ptr; |
84 } | 83 } |
85 | 84 |
86 return ptr; | 85 return ptr; |
87 } | 86 } |