What needs to be fixed so that this "+5" can be removed? What happens if something changes and the magic number needs to be 6? Also, where's the unit test?
What needs to be fixed so that this "+5" can be removed? What happens if something changes and the magic number needs to be 6? Also, where's the unit test?
The comment you originally replied to has a direct link to the (commit that added the) code in question.
You can certainly fix known knowns, but you can't fix unknown unknowns. Sometimes its safer to simply apply a rule that you have confidence will work everywhere than fix that may introduce unsuspecting problems.
Once you identify a root cause, you can assess the scope. "allocate 5 bytes more than you need" is a pretty broad reaching fix. I'd be very hesitant to implement it without proper time to fix.
What would you think if the following were true for a fairly generalized problem:
- It is easy to prove a particular upper bound on memory requirements when calling a function.
- It is very difficult to know exactly what the memory requirements will be for particular input.
- No known input achieves the known upper bound.
Is it a problem if we allocate enough memory to satisfy the bound we can prove, and then don't have a unit test showing we can't do with less?
At first glance the example seems contrived to me. Assuming that the code is deterministic, wouldn't it be trivial to measure the memory requirement for a particular input?
What were you trying to ask?
> - It is easy to prove a particular upper bound on memory requirements
That they should have included said proof in the source code (in a comment if the type system isn't expressive enough to run it).
That way you can trust the estimator to always tell you at most how much memory you'd need.