Parent Directory | Revision Log
Revision 1.3 - (view) (download)
1 : | Isibaar | 1.2 | #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 : | edgomez | 1.3 | uint8_t *mem_ptr; |
8 : | Isibaar | 1.2 | |
9 : | edgomez | 1.3 | 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 : | Isibaar | 1.2 | |
20 : | edgomez | 1.3 | if((tmp = (uint8_t *) malloc(size + alignment)) != NULL) { |
21 : | mem_ptr = (uint8_t *)((uint32_t)(tmp + alignment - 1)&(~(uint32_t)(alignment - 1))); | ||
22 : | *(mem_ptr - 1) = (uint8_t)(mem_ptr - tmp); | ||
23 : | return (void *) mem_ptr; | ||
24 : | } | ||
25 : | } | ||
26 : | |||
27 : | return NULL; | ||
28 : | Isibaar | 1.2 | |
29 : | } | ||
30 : | |||
31 : | void xvid_free(void *mem_ptr) | ||
32 : | { | ||
33 : | |||
34 : | edgomez | 1.3 | uint8_t *real_ptr; |
35 : | |||
36 : | real_ptr = (uint8_t*)mem_ptr; | ||
37 : | |||
38 : | free(real_ptr - *(real_ptr -1)); | ||
39 : | Isibaar | 1.2 | |
40 : | } |
No admin address has been configured | ViewVC Help |
Powered by ViewVC 1.0.4 |