I'm developing some code which has an abstract interface and with some of
the functions it is useful if I pass in a cached value of one of the
parameters which are otherwise calculated in those functions (and
numerically expensive to calculate). The issue is that this cached
parameter will not always be used, so in some cases this is a wasted
passing of data. Also I can envisage future uses where other data may be
required to be passed in, though of course this is perhaps too
future-looking, and that data won't always be used either, of course.
These functions are called a great many times over the course of the
In this case, would it cause any significant efficiency problems if I
move from passing in about 4 parameters, to passing in fewer but with
one of them a struct/class? Clearly you get a reduction in copying of
the function parameters (good), but then accessing of struct members is
probably slightly slower (bad). Having a struct means that I'm able to
extend the code later without changing the interface, and there is no
(direct) overhead of passing in a wasted parameter. I should note that
wrt changing the interface, the change of struct is not an issue since
this will probably be recompiled...this is more a maintenance issue than
binary compatibility, etc.
Probably I should just do a set of tests :)
Thanks for any thoughts,
Neil, going to bed.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]