Mercurial > libavutil.hg
comparison mem.c @ 94:7ac2b9550c6b libavutil
align av_realloc()
author | michael |
---|---|
date | Sun, 13 Aug 2006 00:47:16 +0000 |
parents | 8fb151c4d4c7 |
children | a87f3ae8c46f |
comparison
equal
deleted
inserted
replaced
93:b47203d3711f | 94:7ac2b9550c6b |
---|---|
99 * identical to malloc(size). If size is zero, it is identical to | 99 * identical to malloc(size). If size is zero, it is identical to |
100 * free(ptr) and NULL is returned. | 100 * free(ptr) and NULL is returned. |
101 */ | 101 */ |
102 void *av_realloc(void *ptr, unsigned int size) | 102 void *av_realloc(void *ptr, unsigned int size) |
103 { | 103 { |
104 #ifdef MEMALIGN_HACK | 104 void *ptr2; |
105 int diff; | |
106 #endif | |
107 | 105 |
108 /* let's disallow possible ambiguous cases */ | 106 /* let's disallow possible ambiguous cases */ |
109 if(size > (INT_MAX-16) ) | 107 if(size > (INT_MAX-16) ) |
110 return NULL; | 108 return NULL; |
111 | 109 |
112 #ifdef MEMALIGN_HACK | 110 #ifndef MEMALIGN_HACK |
113 //FIXME this isn't aligned correctly, though it probably isn't needed | 111 ptr= realloc(ptr, size); |
114 if(!ptr) return av_malloc(size); | 112 if(((int)ptr&15) || !ptr) |
115 diff= ((char*)ptr)[-1]; | 113 return ptr; |
116 return realloc(ptr - diff, size + diff) + diff; | |
117 #else | |
118 return realloc(ptr, size); | |
119 #endif | 114 #endif |
115 | |
116 ptr2= av_malloc(size); | |
117 if(ptr && ptr2) | |
118 memcpy(ptr2, ptr, size); | |
119 av_free(ptr); | |
120 | |
121 return ptr2; | |
120 } | 122 } |
121 | 123 |
122 /** | 124 /** |
123 * Free memory which has been allocated with av_malloc(z)() or av_realloc(). | 125 * Free memory which has been allocated with av_malloc(z)() or av_realloc(). |
124 * NOTE: ptr = NULL is explicetly allowed | 126 * NOTE: ptr = NULL is explicetly allowed |