[Haskell-cafe] Storable class?
sebastian.sylvan at gmail.com
Tue Apr 22 17:55:51 EDT 2008
On Tue, Apr 22, 2008 at 10:48 PM, Evan Laforge <qdunkan at gmail.com> wrote:
> > On Tue, Apr 22, 2008 at 9:29 PM, Evan Laforge <qdunkan at gmail.com> wrote:
> > > This uses hsc2hs. As far as I can tell, alignment is unused. I've
> > > never had an error from using 'undefined' there.
> > Some architectures require all sorts of wacky alignments. E.g. floats
> > need to be 4 byte aligned, so it's very important that you don't poke a
> > single byte, and then a float, you need to pad with 3 empty bytes first
> > (assuming the whole structure starts at a 4 byte alignment).
> Does that mean that if ghc is on a sufficiently wacky architecture it
> will evaluate "alignment" and throw undefined? And if that's the case
> it would seem that you can't write "alignment" without introducing
> platform dependencies.
> I've also heard that even on x86, if you don't have things aligned
> properly, structure access will be slow. But I'd assume since I'm
> poking into a C structure, either the C compiler will have taken care
> of alignment or its definition in C will have to include some manual
> padding, and so the haskell side doesn't have to worry about it at
> The FFI doc doesn't really talk about the alignment method at all, so
> I don't really understand how to write one or how it's used.
Well I know that on the Xbox 360 (PowerPC with some extensions basically)
alignment problems will sometimes cause slowness, and sometimes a crash
depending on the data type. I can't remember which ones are which though,
and usually the compiler takes care of it, but in cases such as this when
you're manually poking bytes into a buffer, you do need to be very careful
and make sure that anything actually using these values will either have the
data in the correct alignment right away, or will copy it into an aligned
variable before doing anything with it.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe