Hi,

Am Montag, den 05.11.2012, 23:34 +0100 schrieb Peter Divianszky:
> Good remark, this can be solved with weak pointers, although I don't 
> know how efficient they are.
> 
> ----------------------
> The next version of the proposal
> 
> Replace every record update
> 
>      r' = r { x = y }
> 
> with
> 
>      r' = r { x = update (weak r) r' (x r) y) }
> 
> in generated code if some sharing aware optimization flag is enabled.
> 
> Auxilary functions:
> 
> weak :: a -> Weak a
> -- make a weak pointer which is not followed by GC
> 
> update :: Weak r -> r -> x -> x
> update r_old r_new x_old x_new = unsafePerformIO $ do
>      eval x_new
>      b <- x_old === x_new
>      when b (replace r_new r_old)
>      return x_new
> 
> (===) :: a -> a -> IO Bool
> -- pointer-equality for boxed values, equality for unboxed values
> 
> replace :: a -> Weak a -> IO ()
> -- replace thunks in the heap
> -- do nothing if the weak pointer was gone

better, but still keeping too much stuff in memory: Namely x_old cannot
be freed. For most uses it will be retained by the thunk x_new anyways,
as you intend them to be updates of some kind, but it would probably
still make sense to use a weak pointer for (x r).

You can probably implement this using System.Mem.Weak,
reallyUnsafePtrEquality and unsafePerformIO. Not sure how well it would
perform, given the overhead of managing the Weak pointers.

Greetings,
Joachim

-- 
Joachim "nomeata" Breitner
  m...@joachim-breitner.de  |  nome...@debian.org  |  GPG: 0x4743206C
  xmpp: nome...@joachim-breitner.de | http://www.joachim-breitner.de/

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to