In GHC, how can I allocate a chunk of memory aligned to some block
size (say, 512 or 1024 bytes)? I tried to specify it in the
"alignment" method in the Storable typeclass, but that does not seem
to work. Is Storable.alignment really used in GHC? If so, is there a
code example that allocates aligned memory in this way?

For the moment I am using the C function memalign() like this:

foreign import ccall "static stdlib.h"
 memalign :: CInt -> CInt -> IO (Ptr CChar)
....
 do ptr <- memalign alignment size
    fptr <- newForeignPtr finalizerFree ptr

Is it safe to do so?

Thanks,
Peng
_______________________________________________
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

Reply via email to