Question very simple - say, i got function, which receives array as its arguments
void calc(double[] data)
how do "split" this data in two subarrays and pass to sub functions like this
calc_sub(data(0, length/2));
cals_sub(data(length /2, length /2));
i hope, you got the idea - in c++ i would write this
void calc(double * data, int len)
{
calc_sub(data, len / 2); //this one modifies data!!
calc_sub(data + len / 2, len / 2); //this one modifies data too!!
}
How to do same in C# without unecesary memory copying? I would need 2 memory copies here. 1) from data to splitted data 2) calc_sub 3) from splitted data back to data! This is huge waste of time and memory!
The easiest is probably using LINQs Take and Skip extension methods:
int half = data.Length / 2;
double[] sub1 = data.Take(half).ToArray();
double[] sub2 = data.Skip(half).ToArray();
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