I have a question about unsafe code
functions.
As I have understand I need to use it because I use pointers
.
I am not completely sure how it works. So I will try with some question marks to see if I can sort it out better.
Is it true that unsafe code removes the overhead for the
fixed
variables. With other words. Only those which are declared in the actual fixed statement like this:
fixed (int* ptr = arraynums)
Looking at my code example below. I will have variables that change in size WITHIN the clammers of the above
fixed
statement. Those variables will then bemanaged code
that will have different sizes each iterations of the 1000 iterations.
My question here. Is it perfectly okay to mix managed variables/resources like in my example that takes different sizes and .Counts inside the for (int i = 0; i < 1000; i++)
?
unsafe void testing()
{
int[] arraynums = new int[100000];
fixed (int* ptr = arraynums)
{
for (int i = 0; i < 1000; i++)
{
int[] array1 = new int[58745]; //Will take different number of elements each time
List<String> list1 = new List<String>();
list1.Add(""); //Will add different number of elements each time
StreamWriter streamWriter1; //Write to different files
}
}
}