3 ms·
Recipe for bugs but possibly also a recipe for performance. I’m not making any claims for this particular case, but if a function taking a large buffer to modi
by Someone 6y ago
Recipe for bugs but possibly also a recipe for performance.
I’m not making any claims for this particular case, but if a function taking a large buffer to modify needs some extra space, and the code can get faster by storing that at the end of the buffer, requiring the caller to reserve that space can mean not having to copy the buffer twice, increasing memory use and execution time.
A fairly common example is room for adding extra zero string terminators, so that an vectorized algorithm walking the input always hits one of them.
- asveikau 6y agoI think there are better ways to encode that in API design that are less ambiguous. For example perhaps having a function or some other means to compute required buffer size, in a way that makes such padding requirements relatively opaque to the caller.