number of references to a variable

Is there a way to know the number of memory references for a variable?. The runtime must know it but i do not know if this available for the program trough any low level trick Thanks

"Alberto G. Corona "
Is there a way to know the number of memory references for a variable?. The runtime must know it but i do not know if this available for the program trough any low level trick
Flameproof vests, cheap and safe! Get yours now before it's too late! -- (c) this sig last receiving data processing entity. Inspect headers for copyright history. All rights reserved. Copying, hiring, renting, performance and/or quoting of this signature prohibited.

On 1 Nov 2008, at 16:33, Achim Schneider wrote:
"Alberto G. Corona "
wrote: Is there a way to know the number of memory references for a variable?. The runtime must know it but i do not know if this available for the program trough any low level trick
Flameproof vests, cheap and safe! Get yours now before it's too late!
Save one for me, please!

Alberto G. Corona wrote:
Is there a way to know the number of memory references for a variable?. The runtime must know it but i do not know if this available for the program trough any low level trick
More precisely, the GC computes it each time it runs. (And only computes it precisely during a "major" pass, not the more frequent "minor" passes.) You can attach a finaliser to an object, and that'll allow you to know when the reference count reaches zero. But beyond that, I don't know.

On Nov 1, 2008, at 9:38 AM, Andrew Coppin wrote:
Alberto G. Corona wrote:
Is there a way to know the number of memory references for a variable?. The runtime must know it but i do not know if this available for the program trough any low level trick
More precisely, the GC computes it each time it runs. (And only computes it precisely during a "major" pass, not the more frequent "minor" passes.)
Even this isn't quite true for most GC algorithms. The GC only needs to compute whether there is 0 or >= 1 reference to a given location (with some special weasel words for stuff with finalizers defined). If you can see it, the answer is always >=1, so this information is much less useful than you might think! Usually the clever thing you want to know is "this is the sole reference to the pointed-to object". If that's what you're interested in, try looking up "one-bit reference counting", but note that like any accurate reference counting technique it's really inefficient in practice compared to GC. [There are efficient reference counting techniques, but they defer refcount updates in various subtle ways. Also, every ref count technique requires a cycle detector.] -Jan-Willem Maessen

Jan-Willem Maessen wrote:
On Nov 1, 2008, at 9:38 AM, Andrew Coppin wrote:
Alberto G. Corona wrote:
Is there a way to know the number of memory references for a variable?. The runtime must know it but i do not know if this available for the program trough any low level trick
More precisely, the GC computes it each time it runs. (And only computes it precisely during a "major" pass, not the more frequent "minor" passes.)
Even this isn't quite true for most GC algorithms. The GC only needs to compute whether there is 0 or >= 1 reference to a given location. If you can see it, the answer is always >=1, so this information is much less useful than you might think!
Quite right.
Usually the clever thing you want to know is "this is the sole reference to the pointed-to object".
Does GHC have weak references? (I seem to recall it does...)

Andrew Coppin wrote:
Jan-Willem Maessen wrote:
Usually the clever thing you want to know is "this is the sole reference to the pointed-to object".
Does GHC have weak references? (I seem to recall it does...)
http://www.haskell.org/ghc/docs/latest/html/libraries/base/System-Mem-Weak.h... As for the uniqueness of a reference to an object, there are alternatives to reference-counting techniques. For example, the language Clean[1] builds it into the type system (to replace monads) and they've gotten very good performance results from doing so. There are other linear logic approaches as well, though porting any of these to Haskell would take a fair deal of work to make efficient. Certainly a worthy research goal, but probably not what you had in mind :) [1] http://clean.cs.ru.nl/ -- Live well, ~wren
participants (6)
-
Achim Schneider
-
Alberto G. Corona
-
Andrew Coppin
-
Jan-Willem Maessen
-
Miguel Mitrofanov
-
wren ng thornton