[Haskell-beginners] How long is the pointer from a Vector valid (after it has been extracted by unsafeWidth)

Nathan Hüsken nathan.huesken at posteo.de
Thu Sep 19 14:26:57 CEST 2013


Hey,

Background: I am making a wxhaskell backend for diagrams. Currently I am 
attempting to implement dashing. The function

penSetDashes :: Pen a -> Int -> Ptr c -> IO ()

takes a bit muster, represented by an array of chars (second parameter 
is the number of the used bits).
The problem is, that the underlying C++ function expects the pointer to 
be valid even after the function has been executed (until the pen is 
deleted or another dashing is set).

So I am creating a Vector Word8 with the desired bitmuster and I am 
using Data.Vector.Storable.withUnsafe to pass its internal pointer to 
penSetDashes.

But the pointer must point to something valid even after that!
So I was thinking, what if I define

data MyPen a = MyPen (Pen a) (Vector Word8)

and always keep the vector of dashes with the pen. Will the pointer stay 
valid?

If there are other Ideas on how to this, I am open!

Regards,
Nathan



More information about the Beginners mailing list