Re:The use of `class` for things that should be simple free ...
by jmull on Thursday May 28, 2020 @07:34AM
(#23336090)
If we’re talking about an algorithm as a class, the state managed by the class is algorithm state, not the data the algorithm acts on. The data the algorithm acts on should probably be passed as a parameter regardless of whether the algorithm is implemented as a class or top-level function.
[ Parent
| on HN ]
Re:The use of `class` for things that should be simple free ...
by fluffything on Thursday May 28, 2020 @09:52AM
(#23337224)
> If we’re talking about an algorithm as a class, the state managed by the class is algorithm state, not the data the algorithm acts on.
I was only talking about algorithm state here. Check, for example, how the C++ string searching algorithms work to get a feeling of how these APIs work in the wild. For an example of this gone wrong, look no further than C++ stable_search, which does not let the user reuse the merge sort buffer across searches.
Re:The use of `class` for things that should be simple free ...
by jmull on Thursday May 28, 2020 @01:15PM
(#23339838)
Hm, I guess this is moving in the direction of a debate on semantics and API design... which is independent of the original topic.
I don’t know what stable_search is, but it would be a design decision if/how it supports different memory management options for buffers, and isn’t really affected by the decision to use a class or top-level function for implementation. Either way, buffer allocation could be hidden in the implementation and out of the user’s control or exposed to some degree and under the user’s control.