Move memory file functions out to a separate file

Signed-off-by: Alex Smith <alex@alex-smith.me.uk>