RE: withStorableArray making IORefs

13 Aug
2002
13 Aug
'02
5:34 a.m.
I'm guessing it's not safe to use "newIORef" as the function argument to withStorableArray, but in a simple case [1], it seems to work okay. I suppose the danger is if the RTS decides to move the array. Does this happen IRL?
The danger is rather that the array might get freed. A StorableArray contains a ForeignPtr to the array, and the finalizer on the ForeignPtr will free the array after the last use. If you obtain a pointer to the array by nefarious means (ie. 'withStorableArray return' would do it) then the RTS might free the array while you still have a pointer to it. Cheers, Simon
8317
Age (days ago)
8317
Last active (days ago)
0 comments
1 participants
participants (1)
-
Simon Marlow