alignment
Ross Paterson
ross at soi.city.ac.uk
Mon Jan 13 05:17:12 EST 2003
On Mon, Jan 13, 2003 at 09:00:33PM +1100, Manuel M T Chakravarty wrote:
> Fergus Henderson <fjh at cs.mu.OZ.AU> wrote,
>
> > On 09-Jan-2003, Ross Paterson <ross at soi.city.ac.uk> wrote:
> > > Two additions I think are required:
> > >
> > > 1) The spec should state that mallocBytes and allocaBytes return a block
> > > of memory sufficiently aligned for any of the primitive types supported
> > > by the architecture.
> >
> > I disagree. These routines should only be required to align the memory
> > sufficiently for any of the primitive types which could fit in the amount
> > of space allocated. For example, double precision floats might occupy
> > 8 bytes, and require 8-byte alignment, but four-bytes allocations should
> > not be required to be 8-byte aligned.
> >
> > (This is something the C standard got wrong, IMHO.)
>
> I agree with Fergus.
Yes, that's even better: a C malloc will satisfy this constraint, but so
will others.
> \item[sizeOf~~~~::\ Storable a => a -> Int]
> \item[alignment~::\ Storable a => a -> Int]\combineitems
> [...] We require that all
> the elements of a contiguous array of storable values meet the alignment
> constraint of these values; more formally, we require that
> %
> \begin{quote}
> \begin{verbatim}
> sizeOf v `mod` alignment v == 0
> \end{verbatim}%
> \end{quote}
How about just:
We require that the size is divisible by the alignment.
(Thus each element of a contiguous array of storable values
will be properly aligned if the first one is.)
More information about the FFI
mailing list