Pickling and unpickling objects #
By abusing saveModuleData
and readModuleData
we can pickle and unpickle objects to disk.
Load an object from disk.
Note: The returned CompactedRegion
can be used to free the memory behind the value
of type α
, using CompactedRegion.free
(which is only safe once all references to the α
are
released). Ignoring the CompactedRegion
results in the data being leaked.
Use withUnpickle
to call CompactedRegion.free
automatically.
This function is unsafe because the data being loaded may not actually have type α
, and this
may cause crashes or other bad behavior.
Instances For
unsafe def
withUnpickle
{m : Type → Type u_1}
[Monad m]
[MonadLiftT IO m]
{α : Type}
{β : Type}
(path : System.FilePath)
(f : α → m β)
:
m β
Load an object from disk and run some continuation on it, freeing memory afterwards.