My question is throughout the whole of the Android API a lot of the library calls ask for a results[]
parameter to be passed into method for example:
public boolean isInProximity(double startLat, double startLongitude, float meters) {
float[] results = new float[3];
Location.distanceBetween(startLat, startLongitude, endLatitude, endLongitude, results);
return results[0] <= meters;
}
The call to android is the Location.distanceBetween()
and it requires the results[]
why don't they just include a return signature to the method? I am assuming that it is some kind of memory or speed optimisation. I am unsure on the exact reasoning behind it.
You are correct, it is about optimization, that way you can call this method many times without needing to allocate memory each time.
Edit --
Here is a test so: http://codeyarns.com/2010/10/21/c-return-value-versus-output-parameter/
Better late than never I guess.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With