29.13. Using the fixed keyword
You have seen that pointer types can only be unmanaged types. You can have a pointer of a struct type as long as this struct does not contain any field with a managed type. It is illegal to declare a pointer of a class type because a class is a managed type.
For managed types, the garbage collector is free to shift the actual location of managed objects in memory as the runtime desires. This is usually done for optimizing memory use. As far as the developer or application user is concerned, it doesn't really matter where a particular managed object is stored, as long as the variable referencing that object is updated accordingly with the new address if a shift occurs. The garbage collection is unaware of any pointers, ...
Get From Java to C#: A Developer's Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.