Re: [Jack-Devel] Alignment (again)

PrevNext  Index
DateThu, 04 Aug 2011 12:33:31 +0300
From Sampo Savolainen <[hidden] at iki dot fi>
ToGabriel Beddingfield <[hidden] at gmail dot com>
Cc[hidden] at lists dot jackaudio dot org
In-Reply-ToGabriel Beddingfield [Jack-Devel] Alignment (again)
Follow-UpStéphane Letz Re: [Jack-Devel] Alignment (again)
Follow-UpGabriel Beddingfield 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
PrevNext  Index

1312450426.14704_0.ltw:2,a <CALUWeObT5CNr+krJXNrTwL6uCRWKpbEbw_NRwm2u-L3+c8CRjQ at mail dot gmail dot com>