large array passing to a function

I have a rather large array of data that I want to pass to a function for reading. The function will NOT modify the array, simply read it. what is the most efficient way to pass the array to the function to avoid copying the entire array when the function is called?

Is this even something I should even worry about?

Thanks,
memotick

Is this even something I should even worry about?

No, I can not think of a valid reason to copy an array in this context (and hardly ever in any context). Either pass a pointer or make the array global.


Rob

Graynomad:

Is this even something I should even worry about?

No, I can not think of a valid reason to copy an array in this context (and hardly ever in any context). Either pass a pointer or make the array global.


Rob

Thanks for the reply Rob.

I likely will use a global volatile array because I will be filling it via a timer interrupt... unless there is a simpler solution someone recommends

filling it via a timer interrupt

If they are only 8-bit values that don't rely on each other that's generally safe (see below), but if they are 16 or more bits make sure you disable interrupts whenever you access an array element.

So

byte array[10];
...
byte x = array[y];

Should be safe but

int array[10];
...
int x = array[y];

is not.

Also even if the elements are 8 bits code like this

array[x]++;

is not atomic because it reads/modifies/writes, so it has to be protected by disabling interrupts.


Rob

If your need more help you can post in the PROGRAMMING section too.

Unless you go out of your way, an array passed to a function would naturally be passed by reference not by value, so there is no need to worry about whether it's being copied (it isn't).

I'd be worried about passing in a large array of volatile data, though. The 'large' implies that the function might be doing non-trivial things and you might not want to keep interrupts disabled for the duration, and if interrupts are enabled then you need to be concerned about race conditions where the interrupt handler modifies the data while the function is using it. Does the function actually need to be given the whole array?

raschemmel:
If your need more help you can post in the PROGRAMMING section too.

But don't post the same question in two places - that is very irritating.

...R

Right. Bad choice of words . I meant "You can post in Programming INSTEAD" . Yeah, that's what I meant. Thanks for correcting me.