* Analog of _aligned_malloc * @param size Size of memory being pointed to * @param align_size Size of memory chunks to align to (must be power of 2) */
| 30 | * @param align_size Size of memory chunks to align to (must be power of 2) |
| 31 | */ |
| 32 | void *eedi2_aligned_malloc( size_t size, size_t align_size ) |
| 33 | { |
| 34 | char * ptr, * ptr2, * aligned_ptr; |
| 35 | int align_mask = align_size - 1; |
| 36 | |
| 37 | ptr = (char *)malloc( size + align_size + sizeof( int ) ); |
| 38 | if( ptr==NULL ) return( NULL ); |
| 39 | |
| 40 | ptr2 = ptr + sizeof( int ); |
| 41 | aligned_ptr = ptr2 + ( align_size - ( (size_t)ptr2 & align_mask ) ); |
| 42 | |
| 43 | |
| 44 | ptr2 = aligned_ptr - sizeof( int ); |
| 45 | *( (int *)ptr2 ) = (int)( aligned_ptr - ptr ); |
| 46 | |
| 47 | return( aligned_ptr ); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Analog of _aligned_free |