comparison mem.c @ 2060:d07784fbdad1 libavcodec

optional and disabled by default memalign hack for SSE/SSE2 on that alternative OS
author michael
date Sun, 06 Jun 2004 03:45:53 +0000
parents 1e39f273ecd6
children f980082baeaa
comparison
equal deleted inserted replaced
2059:ad972ab280bc 2060:d07784fbdad1
44 */ 44 */
45 void *av_malloc(unsigned int size) 45 void *av_malloc(unsigned int size)
46 { 46 {
47 void *ptr; 47 void *ptr;
48 48
49 #if defined (HAVE_MEMALIGN) 49 #ifdef MEMALIGN_HACK
50 int diff;
51 ptr = malloc(size+16+1);
52 diff= ((-(int)ptr - 1)&15) + 1;
53 ptr += diff;
54 ((char*)ptr)[-1]= diff;
55 #elif defined (HAVE_MEMALIGN)
50 ptr = memalign(16,size); 56 ptr = memalign(16,size);
51 /* Why 64? 57 /* Why 64?
52 Indeed, we should align it: 58 Indeed, we should align it:
53 on 4 for 386 59 on 4 for 386
54 on 16 for 486 60 on 16 for 486
85 * identical to malloc(size). If size is zero, it is identical to 91 * identical to malloc(size). If size is zero, it is identical to
86 * free(ptr) and NULL is returned. 92 * free(ptr) and NULL is returned.
87 */ 93 */
88 void *av_realloc(void *ptr, unsigned int size) 94 void *av_realloc(void *ptr, unsigned int size)
89 { 95 {
96 #ifdef MEMALIGN_HACK
97 //FIXME this isnt aligned correctly though it probably isnt needed
98 int diff= ptr ? ((char*)ptr)[-1] : 0;
99 return realloc(ptr - diff, size + diff) + diff;
100 #else
90 return realloc(ptr, size); 101 return realloc(ptr, size);
102 #endif
91 } 103 }
92 104
93 /* NOTE: ptr = NULL is explicetly allowed */ 105 /* NOTE: ptr = NULL is explicetly allowed */
94 void av_free(void *ptr) 106 void av_free(void *ptr)
95 { 107 {
96 /* XXX: this test should not be needed on most libcs */ 108 /* XXX: this test should not be needed on most libcs */
97 if (ptr) 109 if (ptr)
110 #ifdef MEMALIGN_HACK
111 free(ptr - ((char*)ptr)[-1]);
112 #else
98 free(ptr); 113 free(ptr);
114 #endif
99 } 115 }
100 116