[email protected]
[Top] [All Lists]

Re: [Haskell-cafe] Explicit garbage collection

Subject: Re: [Haskell-cafe] Explicit garbage collection
From: Edward Kmett
Date: Wed, 6 Jan 2010 15:21:05 -0500
You probably just want to hold onto weak references for your 'isStillNeeded' checks.

Otherwise the isStillNeeded check itself will keep you from garbage collecting!

http://cvs.haskell.org/Hugs/pages/libraries/base/System-Mem-Weak.html

-Edward Kmett

On Wed, Jan 6, 2010 at 9:39 AM, Miguel Mitrofanov <[email protected]> wrote:
I'll take a look at them.

I want something like this:

refMaybe b dflt ref = if b then readRef ref else return dflt
refIgnore ref = return "blablabla"
refFst ref =
 do
  Â(v, w) <- readRef ref
  Âreturn v
test =
 do
  Âa <- newRef "x"
  Âb <- newRef 1
  Âc <- newRef ('z', Just 0)
  ÂperformLocalGC -- if necessary
  Âx <- isStillNeeded a
  Ây <- isStillNeeded b
  Âz <- isStillNeeded c
  Âu <- refMaybe y "t" a -- note that it wouldn't actually read "a",
             Â-- but it won't be known until runtime.
  Âw <- refIgnore b
  Âv <- refFst c
  Âreturn (x, y, z)

so that "run test" returns (True, False, True).


Dan Doel wrote:
On Wednesday 06 January 2010 8:52:10 am Miguel Mitrofanov wrote:
Is there any kind of "ST" monad that allows to know if some STRef is no
Âlonger needed?

The problem is, I want to send some data to an external storage over a
Ânetwork and get it back later, but I don't want to send unnecessary data.

I've managed to do something like that with weak pointers,
ÂSystem.Mem.performGC and unsafePerformIO, but it seems to me that invoking
ÂGC every time is an overkill.

Oh, and I'm ready to trade the purity of runST for that, if necessary.

You may be able to use something like Oleg's Lightweight Monadic Regions to get this effect. I suppose it depends somewhat on what qualifies a reference as "no longer needed".

Âhttp://www.cs.rutgers.edu/~ccshan/capability/region-io.pdf

I'm not aware of anything out-of-the-box that does what you want, though.

-- Dan
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe



_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe
<Prev in Thread] Current Thread [Next in Thread>