Fixed Statement in C#

后端 未结 5 1874
南笙
南笙 2021-01-17 11:51

We have similar code to the following in one of our projects. Can anyone explain (in simple English) why the fixed statement is needed here?

class TestClass
         


        
5条回答
  •  时光取名叫无心
    2021-01-17 12:42

    MSDN has a very similar example. The fixed statement basically blocks garbage collection. In .Net if you use a pointer to a memory location the runtime can reallocate the object to a "better" location at any time. SO if you want to access memory directly you need to fix it in place.

提交回复
热议问题