Mercurial > hg > x
comparison align8.cpp @ 4:92ee28024c05
* Avoid trying to do explicit 32-bit-pointer alignment on 64-bit systems
author | Chris Cannam |
---|---|
date | Tue, 05 Oct 2010 17:03:27 +0100 |
parents | 6422640a802f |
children | 977f541d6683 |
comparison
equal
deleted
inserted
replaced
3:42c078b19e9a | 4:92ee28024c05 |
---|---|
11 | 11 |
12 Returns pointer to a memory block of $size starting at an address divisible by 8. | 12 Returns pointer to a memory block of $size starting at an address divisible by 8. |
13 */ | 13 */ |
14 void* malloc8(unsigned size) | 14 void* malloc8(unsigned size) |
15 { | 15 { |
16 #if (!defined(__SIZEOF_POINTER__) || (__SIZEOF_POINTER__ == 4)) | |
16 char *buffer, *result; | 17 char *buffer, *result; |
17 buffer=(char*)malloc(size+8+sizeof(void*)); | 18 buffer=(char*)malloc(size+8+sizeof(void*)); |
18 if(!buffer) return(NULL); | 19 if(!buffer) return(NULL); |
19 char* tmp=&buffer[sizeof(void*)]; | 20 char* tmp=&buffer[sizeof(void*)]; |
20 result=&((char*)((unsigned)tmp&0xFFFFFFF8))[8]; | 21 result=&((char*)((unsigned)tmp&0xFFFFFFF8))[8]; |
21 ((void**)result)[-1]=buffer; | 22 ((void**)result)[-1]=buffer; |
22 return(result); | 23 return(result); |
24 #else | |
25 return malloc(size); | |
26 #endif | |
23 }//malloc8 | 27 }//malloc8 |
24 | 28 |
25 /* | 29 /* |
26 function free8: deallocation for malloc8() | 30 function free8: deallocation for malloc8() |
27 | 31 |
28 No return value. | 32 No return value. |
29 */ | 33 */ |
30 void free8(void* buffer8) | 34 void free8(void* buffer8) |
31 { | 35 { |
32 if (buffer8) free(((void**)buffer8)[-1]); | 36 #if (!defined(__SIZEOF_POINTER__) || (__SIZEOF_POINTER__ == 4)) |
37 if (buffer8) free(((void**)buffer8)[-1]); | |
38 #else | |
39 free(buffer8); | |
40 #endif | |
33 }//free8 | 41 }//free8 |
42 |