Dynamic memory allocation and deep copy