user1499: I have some really long global variable arrays filled with data.
There is a single function that processes the data. The function works on only one array everytime. This arrays value changes every iteration and gets the value from the global variable arrays.
Since i declare lots of global variable arrays, in order to pass them to the array_to_be_processed_by_the function, the memory is filled up really quickly.
What is the best way to conditionally give values to the array?
For example, there could be a counter in the program, and if the counter is a particular value, the array would be initialized with certain data. Of course, i would also have to call the function, and i would have to keep track of the counter and increase it and zero it at the beginning of the loop, to start from the beginning.
In this approach, only one variable would always be initialized.
PSEUDOCODE:
int looper = 0;

void loop()
{
  switch(looper)
  {
     case 0:
        my_array[] = {DATA HERE};
        exec_func(myarray);
        looper++;
        continue;
     case 1:
         ......
     case 'last_case':
         ...
         looper = 0;
         break;
  }
}

However, i am not sure if this approach is the correct one.
Especially for a microcontroller.
One obvious issue, is that the array values are not necessarily the same size.
Therefore, the base array should be destroyed at each case?
If this is good approach, should new/delete be used on an arduino?
What is the best approach to conditionally initialize an array, so that i don't get out of memory

user7508: Let's consider this:
case 0:
    my_array[] = {DATA HERE};
    exec_func(myarray);

This is not quite valid C++, but let's pretend you get the syntax right
to make it work. The problem is: doing this will not help you save
memory. Where do you think the compiler is going to store {DATA HERE}?
In memory, right. It will be stored as an anonymous array. Then the
initialization of my_array will make a second copy of the data in
memory, this time in a named array.
You can avoid this second copy by naming your arrays of constants, and
passing the correct one to your function:
// At global scope:
const int my_array_0[] = {...};
const int my_array_1[] = {...};

// Within the switch/case:
case 0:
    exec_func(my_array_0);

You can even avoid the switch/case altogether by using an array of
pointers, but that is irrelevant to your current problem.
Your idea of initializing only the array you actually need can work if
you manage to do it procedurally, i.e. implementing some recipe with
instructions, rather than copying a set of constant:
case 0: {
    int my_array[array_size];
    for (int i = 0; i < array_size; i++) {
        my_array[i] = some_expression_to_compute_this_array_item;
    }
    exec_func(myarray);
}

This is not always feasible though.
If you really have to store the constants in the program, and you are
using an AVR-based Arduino (like the Uno, Mega, Micro...), then you can
save RAM by storing the arrays of constants in flash memory, and copying
only the one you need to RAM:
// At global scope:
const int my_array_0[] PROGMEM = {...};
const int array_size_0 = sizeof my_array_0 / sizeof my_array_0[0];
const int my_array_1[] PROGMEM = {...};
const int array_size_1 = sizeof my_array_1 / sizeof my_array_1[0];

// Within the switch/case:
case 0: {
    int my_array[array_size_0];  // array in RAM
    memcpy_P(my_array, my_array_0, sizeof my_array);
    exec_func(my_array);
}
case 1: {
    int my_array[array_size_1];  // array in RAM
    memcpy_P(my_array, my_array_1, sizeof my_array);
    exec_func(my_array);
}

Check the documentations of PROGMEM and memcpy_P() for
the details.
If you go this route, you may consider modifying the function
exec_func() so that it expects its parameter to be a pointer to flash
instead of a pointer to RAM. Then you will completely avoid the copy in
RAM.

Edit: expanding on the idea of passing a pointer to flash.
The C++ compiler doesn't really know the difference between a pointer to
RAM and a pointer to flash. If you want to pass a pointer to flash to a
function, you have to write the function in such a way that it expects a
pointer to flash. For example, this function prints out the contents of
a flash-based array:
// The argument should be a pointer to flash.
void exec_func(const int *data)
{
    for (int i = 0; i < array_size; i++) {
        int number = pgm_read_word(&data[i]);
        Serial.println(number);
    }
}

Note that the array is not accessed directly (evaluating data[i] would
give garbage). Instead, the address of the element you want (&data[i],
a flash address) is passed to the macro pgm_read_word(), which uses
inline assembly to get the relevant data from the flash.
Now you can call this function passing it the address of a PROGMEM
array, as in exec_func(my_array_0);.
Just for completeness, I will show you how to use an array of pointers
to avoid the switch/case construct:
const int my_array_0[] PROGMEM = {...};
const int my_array_1[] PROGMEM = {...};
...

const int *arrays[] = {my_array_0, my_array_1, ...};

int looper = 0;

void loop()
{
    exec_func(arrays[looper]);
    if (++looper == number_of_arrays) looper = 0;
}

Note that here arrays is a RAM-based array. That's why you can access
the elements directly as arrays[looper]. These elements, however, are
pointers to flash-based arrays. If you have so many arrays that arrays
gets too big, you might consider putting it also in flash.

1499: <p>I have some really long global variable arrays filled with data.</p>
<p>There is a single function that processes the data. The function works on only one array everytime. This arrays value changes every iteration and gets the value from the global variable arrays.</p>
<p>Since i declare lots of global variable arrays, in order to pass them to the array_to_be_processed_by_the function, the memory is filled up really quickly.</p>
<p>What is the best way to conditionally give values to the array?</p>
<p>For example, there could be a counter in the program, and if the counter is a particular value, the array would be initialized with certain data. Of course, i would also have to call the function, and i would have to keep track of the counter and increase it and zero it at the beginning of the loop, to start from the beginning.</p>
<p>In this approach, only one variable would always be initialized.</p>
<pre><code>PSEUDOCODE:
int looper = 0;

void loop()
{
  switch(looper)
  {
     case 0:
        my_array[] = {DATA HERE};
        exec_func(myarray);
        looper++;
        continue;
     case 1:
         ......
     case 'last_case':
         ...
         looper = 0;
         break;
  }
}
</code></pre>
<p>However, i am not sure if this approach is the correct one.
Especially for a microcontroller.</p>
<p>One obvious issue, is that the array values are not necessarily the same size.
Therefore, the base array should be destroyed at each <code>case</code>?
If this is good approach, should <code>new/delete</code> be used on an arduino?</p>
<p>What is the best approach to conditionally initialize an array, so that i don't get out of memory</p>
 7508: <p>Let's consider this:</p>
<pre class="lang-cpp prettyprint-override"><code>case 0:
    my_array[] = {DATA HERE};
    exec_func(myarray);
</code></pre>
<p>This is not quite valid C++, but let's pretend you get the syntax right
to make it work. The problem is: doing this will not help you save
memory. Where do you think the compiler is going to store <code>{DATA HERE}</code>?
In memory, right. It will be stored as an <em>anonymous</em> array. Then the
initialization of <code>my_array</code> will make a <em>second copy</em> of the data in
memory, this time in a named array.</p>
<p>You can avoid this second copy by naming your arrays of constants, and
passing the correct one to your function:</p>
<pre class="lang-cpp prettyprint-override"><code>// At global scope:
const int my_array_0[] = {...};
const int my_array_1[] = {...};

// Within the switch/case:
case 0:
    exec_func(my_array_0);
</code></pre>
<p>You can even avoid the <code>switch</code>/<code>case</code> altogether by using an array of
pointers, but that is irrelevant to your current problem.</p>
<p>Your idea of initializing only the array you actually need can work if
you manage to do it <em>procedurally</em>, i.e. implementing some recipe with
instructions, rather than copying a set of constant:</p>
<pre class="lang-cpp prettyprint-override"><code>case 0: {
    int my_array[array_size];
    for (int i = 0; i &lt; array_size; i++) {
        my_array[i] = some_expression_to_compute_this_array_item;
    }
    exec_func(myarray);
}
</code></pre>
<p>This is not always feasible though.</p>
<p>If you really have to store the constants in the program, and you are
using an AVR-based Arduino (like the Uno, Mega, Micro...), then you can
save RAM by storing the arrays of constants in flash memory, and copying
only the one you need to RAM:</p>
<pre class="lang-cpp prettyprint-override"><code>// At global scope:
const int my_array_0[] PROGMEM = {...};
const int array_size_0 = sizeof my_array_0 / sizeof my_array_0[0];
const int my_array_1[] PROGMEM = {...};
const int array_size_1 = sizeof my_array_1 / sizeof my_array_1[0];

// Within the switch/case:
case 0: {
    int my_array[array_size_0];  // array in RAM
    memcpy_P(my_array, my_array_0, sizeof my_array);
    exec_func(my_array);
}
case 1: {
    int my_array[array_size_1];  // array in RAM
    memcpy_P(my_array, my_array_1, sizeof my_array);
    exec_func(my_array);
}
</code></pre>
<p>Check the documentations of <a href="https://www.arduino.cc/reference/en/language/variables/utilities/progmem/" rel="nofollow noreferrer">PROGMEM</a> and <a href="https://www.nongnu.org/avr-libc/user-manual/group__avr__pgmspace.html#gad92fa2ebe26e65fa424051047d21a0eb" rel="nofollow noreferrer"><code>memcpy_P()</code></a> for
the details.</p>
<p>If you go this route, you may consider modifying the function
<code>exec_func()</code> so that it expects its parameter to be a pointer to flash
instead of a pointer to RAM. Then you will completely avoid the copy in
RAM.</p>
<hr />
<p><strong>Edit:</strong> expanding on the idea of passing a pointer to flash.</p>
<p>The C++ compiler doesn't really know the difference between a pointer to
RAM and a pointer to flash. If you want to pass a pointer to flash to a
function, you have to write the function in such a way that it expects a
pointer to flash. For example, this function prints out the contents of
a flash-based array:</p>
<pre class="lang-cpp prettyprint-override"><code>// The argument should be a pointer to flash.
void exec_func(const int *data)
{
    for (int i = 0; i &lt; array_size; i++) {
        int number = pgm_read_word(&amp;data[i]);
        Serial.println(number);
    }
}
</code></pre>
<p>Note that the array is not accessed directly (evaluating <code>data[i]</code> would
give garbage). Instead, the address of the element you want (<code>&amp;data[i]</code>,
a flash address) is passed to the macro <code>pgm_read_word()</code>, which uses
inline assembly to get the relevant data from the flash.</p>
<p>Now you can call this function passing it the address of a <code>PROGMEM</code>
array, as in <code>exec_func(my_array_0);</code>.</p>
<p>Just for completeness, I will show you how to use an array of pointers
to avoid the <code>switch</code>/<code>case</code> construct:</p>
<pre class="lang-cpp prettyprint-override"><code>const int my_array_0[] PROGMEM = {...};
const int my_array_1[] PROGMEM = {...};
...

const int *arrays[] = {my_array_0, my_array_1, ...};

int looper = 0;

void loop()
{
    exec_func(arrays[looper]);
    if (++looper == number_of_arrays) looper = 0;
}
</code></pre>
<p>Note that here <code>arrays</code> is a RAM-based array. That's why you can access
the elements directly as <code>arrays[looper]</code>. These elements, however, are
pointers to flash-based arrays. If you have so many arrays that <code>arrays</code>
gets too big, you might consider putting it also in flash.</p>
