Convert the allocated memory to the correct type