Copy the memory from off-heap to on-heap and some code style modification