Partial fix for #2917
authorSimon Marlow <marlowsd@gmail.com>
Thu, 5 Mar 2009 15:41:53 +0000 (15:41 +0000)
committerSimon Marlow <marlowsd@gmail.com>
Thu, 5 Mar 2009 15:41:53 +0000 (15:41 +0000)
commit18ddadf0b8e35084a51f2560c3fe24ca8a2f3fea
tree460a7c5f06eae74e5ba7da02f0006ff95b3e8096
parent7a116d901e41b6f7e691a02c0107d0254a8e3e19
Partial fix for #2917

 - add newAlignedPinnedByteArray# for allocating pinned BAs with
   arbitrary alignment

 - the old newPinnedByteArray# now aligns to 16 bytes

Foreign.alloca will use newAlignedPinnedByteArray#, and so might end
up wasting less space than before (we used to align to 8 by default).
Foreign.allocaBytes and Foreign.mallocForeignPtrBytes will get 16-byte
aligned memory, which is enough to avoid problems with SSE
instructions on x86, for example.

There was a bug in the old newPinnedByteArray#: it aligned to 8 bytes,
but would have failed if the header was not a multiple of 8
(fortunately it always was, even with profiling).  Also we
occasionally wasted some space unnecessarily due to alignment in
allocatePinned().

I haven't done anything about Foreign.malloc/mallocBytes, which will
give you the same alignment guarantees as malloc() (8 bytes on
Linux/x86 here).
Foreign/Marshal/Alloc.hs
GHC/ForeignPtr.hs