Using C# Pointers

后端 未结 3 727
死守一世寂寞
死守一世寂寞 2021-01-11 17:24

How does c# makes use of pointers? If C# is a managed language and the garbage collector does a good job at preventing memory leaks and freeing up memory properly, then what

3条回答
  •  孤城傲影
    2021-01-11 18:14

    C# supports pointers in a limited way. In C# pointer can only be declared to hold the memory address of value types and arrays. Unlike reference types, pointer types are not tracked by the default garbage collection mechanism. Pointers are also not allowed to point to a reference type or even to a structure type which contains a reference type. So, in pure C#, they have rather limited uses. If used in 'unsafe' code, they would be considered pretty unsafe (of course!).

提交回复
热议问题