[Haskell-cafe] Stable pointers: use of cast to/from Ptr

Donn Cave donn at avvanta.com
Mon Feb 13 16:29:30 CET 2012


Quoth =?ISO-8859-1?Q?Yves_Par=E8s?= <yves.pares at gmail.com>,

> You mean I have to use a type like StablePtr (IORef Stuff)?
> Because there I can only "peek" (deRefStablePtr) the pointer, not "poke" it.
>
> I take it I should return to C a StablePtr to the new value if I don't want
> to use IORefs...

Yes ...

> Or else I have to use regular Ptrs with Foreign.Marshall.Alloc.malloc

yes!

Both of these are good ways, to do different things.  In your initial
message, you asked about a foreign function modifying a value in storage
accessible from Haskell - that's regular Ptr.  Either way, read or write,
communication with the foreign layer is through Ptr, not StablePtr.

StablePtr is for Haskell expressions, which would be totally inscrutable
to the foreign function anyway, and which naturally do not expect to
be modified, so yes, a new value shall be attached to a new StablePtr.

	Donn



More information about the Haskell-Cafe mailing list