Sorry for asking this question, I have been Googling a bit but it seems what comes up is references to clone or copy methods, not an actual answer for my question in C#.
I have two arrays of bytes, and they are being accessed by two threads.
private byte[] buffer1 = new byte[size];
private byte[] buffer2 = new byte[size];
My goal is to write in buffer1 in Thread1, grab a mutex, switch the pointers around and repeat the process. Thread2 would grab a mutex and always read buffer2.
The goal is that Thread2 runs fast and is not affected by the copy taking place in Thread1.
I am very unclear what happens when I do the following:
byte[] temp = buffer1;
buffer1 = buffer2;
buffer2 = temp;
Are the pointers being switched or is the content of buffer2 being copied to buffer1? It should be a simple question but I can't seem to find the solution. Thread1 is doing a Marshal.Copy(), and I don't want the call to impact Thread2.
buffer1andbuffer2end up referencing to the same array. I assume you meant to usetempsomewhere in a classic swap.Buffer.BlockCopy()also