Re: [Jack-Devel] Alignment (again)
On Thu, Aug 4, 2011 at 7:24 AM, Gabriel Beddingfield <[hidden]>wrote:
>
> I ran into a strange bug where the conclusion was that:
>
> float *buf = malloc(512*sizeof(float));
>
> Is invalid/undefined code. I don't have a copy of the C spec, but the C++
> spec says, that since a `float` must be 4-byte aligned... so must a
> `float*`.[1] However, malloc(3) has no alignment requirements.
>
> This is a problem because, for instance, this is how Jack's ringbuffer
> allocates the buffer. And then we turn around and use it for an array of
> float's.
>
> In practice, this bug only rears its head when compiling with -O3 and some
> implementations libc.[2]
>
>
I would be very surprised if malloc() returned pointers that are not 4-byte
aligned. Are you running vectorized code? x86 SIMD (SSE) vector instructions
require 16-byte aligned data pointers. This is a more likely source for the
segfaults.
But, +1 for posix_memalign()
Sampo
1312450426.14704_0.ltw:2,a <CALUWeObT5CNr+krJXNrTwL6uCRWKpbEbw_NRwm2u-L3+c8CRjQ at mail dot gmail dot com>