test & write memory manager.

This implements memory manager.