alignment

Manuel M T Chakravarty chak at cse.unsw.edu.au
Tue Jan 14 07:19:28 EST 2003


Ross Paterson <ross at soi.city.ac.uk> wrote,

> 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.

It now requires,

  The block of memory is sufficiently aligned for any of the
  basic foreign types (see Section~\ref{sec:foreign-types})
  that fits into a memory block of the allocated size.

> > \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.)

Ok, I am using your more concise wording.

Cheers,
Manuel



More information about the FFI mailing list