Added a memory manager

Added a port of memory manager, need tests.