I am having a bit of problem understanding with how arrays they handle their memory. I am pretty bad at explaining in words, so I’ll write you some code 🙂
string[] arr1 = new string[10];
string[] arr2 = new string[10];
/* Fill 'arr1' with random strings */
for(int i = 0; i < 10; i++)
{
arr2[i] = arr1[i]
}
Does this take 2x (size of strings in arr1 and arr2) of memory?
Initially the answer seemed pretty obvious “no” to me, but then I remember that array, with all of its elements, are stored in big continious chunk of memory for fast indexing, so at the moment I have no idea 🙂
The first array contains ten references to strings, so it needs memory to keep them. The same applies to the second array.
But the strings are stored separately. And if you copy the strings from one array to the other, no additional memory is allocated.
So, in your case, the total memory consumed is (ignoring overhead):
arr1arr2