Revision 36157009

View differences:

libavcodec/utils.c
20 20
#include <stdio.h>
21 21
#include <string.h>
22 22
#include <errno.h>
23
#include <limits.h> /* __GLIBC__ and __GLIBC_MINOR__ are defined here */
24
#if __GLIBC__ >=2 && __GLIBC_MINOR__ >= 1 /* Fixme about glibc-2.0 */
25
#define HAVE_MEMALIGN 1
26
#include <malloc.h>
27
#endif
23 28
#include "common.h"
24 29
#include "dsputil.h"
25 30
#include "avcodec.h"
......
28 33
void *av_mallocz(int size)
29 34
{
30 35
    void *ptr;
36
#if defined ( ARCH_X86 ) && defined ( HAVE_MEMALIGN )
37
/*
38
   From glibc-2.1.x manuals:
39
   -------------------------
40
   The address of a block returned by `malloc' or `realloc' in the GNU
41
system is always a multiple of eight (or sixteen on 64-bit systems).
42
If you need a block whose address is a multiple of a higher power of
43
two than that, use `memalign' or `valloc'.  These functions are
44
declared in `stdlib.h'.
45

  
46
   With the GNU library, you can use `free' to free the blocks that
47
`memalign' and `valloc' return.  That does not work in BSD,
48
however--BSD does not provide any way to free such blocks.
49
*/
50
    ptr = memalign(64,size);
51
    /* Why 64? 
52
       Indeed, we should align it:
53
         on 4 for 386
54
         on 16 for 486
55
	 on 32 for 586, PPro - k6-III
56
	 on 64 for K7 (maybe for P3 too).
57
       Because L1 and L2 caches are aligned on those values.
58
       But I don't want to code such logic here!
59
     */
60
#else
31 61
    ptr = malloc(size);
62
#endif
32 63
    if (!ptr)
33 64
        return NULL;
34 65
    memset(ptr, 0, size);

Also available in: Unified diff