Reputation: 2957
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?
Upvotes: 15
Views: 1286
Reputation: 62818
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.)
Upvotes: 4