- const size_t i_alloc = i_size + 2 * BLOCK_PADDING_SIZE + BLOCK_ALIGN;
- block_sys_t *p_sys = malloc( sizeof( *p_sys ) + i_alloc );
+ block_sys_t *p_sys;
+ uint8_t *buf;
+
+#define ALIGN(x) (((x) + BLOCK_ALIGN - 1) & ~(BLOCK_ALIGN - 1))
+#if 0 /*def HAVE_POSIX_MEMALIGN */
+ /* posix_memalign(,16,) is much slower than malloc() on glibc.
+ * -- Courmisch, September 2009, glibc 2.5 & 2.9 */
+ const size_t i_alloc = ALIGN(sizeof(*p_sys)) + (2 * BLOCK_PADDING)
+ + ALIGN(i_size);
+ void *ptr;
+
+ if( posix_memalign( &ptr, BLOCK_ALIGN, i_alloc ) )
+ return NULL;
+
+ p_sys = ptr;
+ buf = p_sys->p_allocated_buffer + (-sizeof(*p_sys) & (BLOCK_ALIGN - 1));