purescript-native
purescript-native copied to clipboard
Safe heap allocation via ST
This is not my area of expertise, but it seems like ST
would be a nice way to use the type system to avoid reference counting. Would this be possible?
The idea is that we would malloc
and delete
the appropriate things in runST
, and stack allocate everything else.
I'm not sure how this would affect things like sharing in data structures.
I think using something like this as a memory management option is a great idea. I've also wondered about the use of effects for it too. The plan is definitely to have a default memory management mechanism in place, but to allow such alternatives (as well as something like the Boehm libgc
or other GCs).
FYI, reference counting is currently only used for data
and records, everything else is handled by value (i.e. on the stack).
This should be pretty easy to do now: https://github.com/andyarvanitis/pure11/wiki/Memory#unmanaged-data