|
System.Mem.StableName | Portability | non-portable | Stability | experimental | Maintainer | libraries@haskell.org |
|
|
|
|
|
Description |
Stable names are a way of performing fast (O(1)), not-quite-exact
comparison between objects. Stable names solve the following problem: suppose you want to build
a hash table with Haskell objects as keys, but you want to use
pointer equality for comparison; maybe because the keys are large
and hashing would be slow, or perhaps because the keys are infinite
in size. We can't build a hash table using the address of the
object as the key, because objects get moved around by the garbage
collector, meaning a re-hash would be necessary after every garbage
collection.
|
|
Synopsis |
|
|
|
|
Stable Names |
|
data StableName a |
An abstract name for an object, that supports equality and hashing. Stable names have the following property: The reverse is not necessarily true: if two stable names are not
equal, then the objects they name may still be equal. Stable Names are similar to Stable Pointers (StablePtr),
but differ in the following ways: There is no freeStableName operation, unlike StablePtrs.
Stable names are reclaimed by the runtime system when they are no
longer needed. There is no deRefStableName operation. You can't get back from
a stable name to the original Haskell object. The reason for
this is that the existence of a stable name for an object does not
guarantee the existence of the object itself; it can still be garbage
collected.
| Instances | |
|
|
makeStableName :: a -> IO (StableName a) |
Makes a StableName for an arbitrary object. The object passed as
the first argument is not evaluated by makeStableName. |
|
hashStableName :: StableName a -> Int |
Convert a StableName to an Int. The Int returned is not
necessarily unique; several StableNames may map to the same Int
(in practice however, the chances of this are small, so the result
of hashStableName makes a good hash key). |
|
Produced by Haddock version 0.4 |