Implemented Memory class with dynamic size