[RDY] Extract memory.c from misc2.c

@philix great work on memory handling deserves its own home! ref #209

Is the name OK?