.NET Garbage Collection, C ++ / CLI interior_ptr and Thread Safety

Therefore, I understand that interior_ptr<typename>you can use it to work with arrays of structures in the same way as in C♯, with the help of an operator fixed, but it does not fix the array on the heap and allows garbage collection. This is good since I do not want to stop the garbage collector from working efficiently. However, the garbage collector runs on a separate thread, and when it is active, all other threads stop when objects in the heap are compacted.

I suggested that I have the following code:

interior_ptr<unsigned char> sourceBufferPtr = reinterpret_cast<interior_ptr<unsigned char>>(&sourceBuffer[0]) + sourceOffset;

The code should execute as follows:

  • &sourceBuffer[0] returns the address of the first element in the array: 32.
  • sourceOffset: 8.
  • reinterpret_cast<interior_ptr<unsigned char>>(&sourceBuffer[0])returns the address interior_ptr<unsigned char>that is added to sourceOffset.
  • sourceBufferPtr must be equal ...
    • 40 if the garbage collector did not move the array.
    • 24, , 16.
    • 40, 3 4, 3 16, , sourceBufferPtr, 40.

, 3 4 , , sourceBufferPtr Common Language Runtime - , , / ? interior_ptr<typename>?

+3
1

, 3 4 , , sourceBufferPtr?

, . reinterpret_cast unmaanged , GC, . inner_ptr :

interior_ptr<unsigned char> bufferPtr = &sourceBuffer[0];
interior_ptr<unsigned char> sourceBufferPtr = bufferPtr + sourceOffset;

_. - inner_ptr.

+3

All Articles