Time cost of simple function/method calls

BlitzMax Forums/BlitzMax Programming/Time cost of simple function/method calls

Just what I was worrying over, if your going to have the method to get and set fields/properties, and it is faster to not use them so often, why bother localizing the field? Won't that just add to the memory? In that case it would make more sense to just access the fields directly.


Local variables do not take memory. They are converted by the compiler to register accesses, which are fast. Only if you have like 10+ locals in a function, some may take actual memory, but even then there is probably no faster way to accomplish the same.

The only reason I prefer using methods for get/set is because in the future it might be necessary to do some operations before setting/getting the given field, or if things need to be changed internally with the field, the code already in place usually doesn't need to be changed.


That's a very good reason for giving a get/set interface to external code. Remember, premature optimization is the root of all evil. Do what seems cleanest and most convenient; worry about efficiency in the unlikely case that it ever becomes a problem.