ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/trunk/xvidcore/src/utils/mem_align.c
(Generate patch)

Comparing trunk/xvidcore/src/utils/mem_align.c (file contents):
Revision 40 by Isibaar, Fri Mar 8 02:46:11 2002 UTC vs.
Revision 41 by Isibaar, Wed Mar 20 00:28:02 2002 UTC

# Line 0 | Line 1
1 + #include <stdlib.h>
2 + #include <stdio.h>
3 + #include "mem_align.h"
4 +
5 + void *xvid_malloc(size_t size, uint8_t alignment)
6 + {
7 +  uint8_t *mem_ptr;
8 +  
9 +  if(alignment == 0)
10 +  {
11 +          if((mem_ptr = (uint8_t *) malloc(size + 1)) != NULL) {
12 +                *mem_ptr = 0;
13 +                return (void *) mem_ptr++;
14 +          }
15 +  }
16 +  else
17 +  {
18 +          uint8_t *tmp;
19 +        
20 +          if((tmp = (uint8_t *) malloc(size + alignment)) != NULL) {
21 +                mem_ptr = (uint8_t *) (((uint32_t) tmp / alignment) * alignment + alignment);
22 +                *(mem_ptr - 1) = (alignment - 1) - ((uint32_t) tmp % alignment);
23 +                return (void *) mem_ptr;
24 +          }
25 +  }
26 +
27 +  return NULL;
28 + }
29 +
30 + void xvid_free(void *mem_ptr)
31 + {
32 +  uint8_t *tmp;
33 +
34 +  tmp = (uint8_t *) mem_ptr - 1;
35 +  mem_ptr  = tmp - *tmp;
36 +
37 +  free(mem_ptr);
38 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines