[Fwd: Memory corruption issues when using newAlignedPinnedByteArray, GC kicking in?]

Nicolas Trangez nicolas at incubaid.com
Wed Jul 11 16:00:31 CEST 2012

On Wed, 2012-07-11 at 09:50 +0100, Simon Marlow wrote:
> On 10/07/2012 23:03, Nicolas Trangez wrote:
> > All,
> >
> > I sent this mail to Haskell Cafe earlier today, and was pointed [1] at
> > this list. As such...
> >
> > Any help/advice would be greatly appreciated!
> It looks like you're making a ForeignPtr from the Addr# or Ptr that 
> points to the contents of the ByteArray#.  Since this ForeignPtr doesn't 
> keep the original ByteArray# alive, the GC will collect it.  You need to 
> keep a reference to the ByteArray# too.

Even though I suspected this and it's blatantly obvious, I failed to
recognize the ForeignPtr as returned by mallocPlainForeignPtrBytes keeps
the reference. Stupid me. Thanks.

> Basically you need a version of mallocForeignPtrBytes that has supports 
> alignment.  Unfortunately it's not possible to write one because the 
> internals of ForeignPtrContents are not exported - we had a recent 
> ticket about that (http://hackage.haskell.org/trac/ghc/ticket/7012) and 
> in 7.6.1 we will export the necessary internals.  If you want we could 
> also add mallocForeignPtrAlignedBytes - please send a patch.




More information about the Glasgow-haskell-users mailing list