>which is duplicated work
The caller can allocate memory to be shared between the 2 function calls to avoid needing duplicate work
The caller can allocate memory to be shared between the 2 function calls to avoid needing duplicate work
With the approach of having the caller allocate you have carefully design the API to make it possible.