This is common in functional languages especially with TCO. I was just wondering if it provided any performance benefits besides being easier to write and keep track of. Is it just as fast to access the variables in the struct as it is to access them if they were just normal arguments? Is there any cons to this method?
This is common in functional languages especially with TCO. I was just wondering if
Share
There is no benefit, because structs are passed by value. Passing multiple arguments one by one will take the same amount of allocations from a running program as the allocation of a
struct. Moreover,structmay give you worse results because of padding.Even if you pass your
structby pointer, you would still need to allocate a new instance of yourstructbefore passing it to the next level of invocation. Theoretically, you could get some benefit by reusing a struct that you have allocated once in multiple invocations, but in most cases that would be a micro-optimization not worth your trouble (unless your profiler indicates otherwise).