I'm creating a program which implements some kind of cache. I need to use as much memory as possible and to do that I need to do two things:
I need a platform independent solution (Linux, Windows, etc.).
Using these two pieces of information I will reduce the size of cache or enlarge it. How can I get this information in Haskell? Are there any packages that can provide that information?
Haskell computations produce a lot of memory garbage - much more than conventional imperative languages. It's because data are immutable so the only way to store every next operation's result is to create new values. In particular, every iteration of a recursive computation creates a new value.
By default, Haskell heap objects are stored “boxed” — they are represented as a pointer to an object on the heap.
I can't immediately see how to do this portably.
However, GHC does have "weak pointers". (See System.Mem.Weak
.) If you create items and hang on to them via weak pointers (only), then the garbage collector will automatically start deleting items if you run low on physical memory.
(Unfortunately, this doesn't give you the ability to decide which items to delete first — e.g., the ones that are cheapest to recreate or the ones that have been least-used or something.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With