O'Reilly logo

From Java to C#: A Developer's Guide by Heng Ngee Mok

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required