3 ms·
>which is duplicated work The caller can allocate memory to be shared between the 2 function calls to avoid needing duplicate work
by charcircuit 3y ago
>which is duplicated work
The caller can allocate memory to be shared between the 2 function calls to avoid needing duplicate work
- vore 3y agoHow do you know how much memory you need to allocate when you need to do the work in the first place to determine it? Maybe if snprintf was resumable by supplying a larger buffer while it was doing its work, but this seems like a lot of complexity.
- charcircuit 3y agoIn this case the state takes a constant amount of space so it is just a matter of allocating a single struct. With the approach of having the caller allocate you have carefully design the API to make it possible.