Separate memory system code from mesh code

Moved data structures, definitions, functions, etc. out of mesh.h/.c
and into new mem.h/.c files.