Ownership for Fortran pointers

type :: heavy_type
real a(11111,22222)
end type

class(*), allocatable :: a1
class(heavy_type), allocatable :: a2

allocate(heavy_type :: a1)

! task: move memory from a1 to a2 without a copy
! problem encountered whenever you want to build
! any kind of generic container without using pointers

And the type of the algorithm is not relevant, since pointer and allocatable cannot change their “flavor” (they cannot be converted between each other, as you mentioned), you either have to stick to one or another in the entire code (unless you want to make another copy).