ANSWER: POP QUIZ: Why should we pin a managed object?

Thank you to everyone for answering the quiz.  Seems like I started out with an easy question as everyone answered correctly.

Congrats to Timothy Fries for being the first to answer and also for having such a complete answer.

The answer:

You pin a managed object before you are going to make a call outside of the managed world (making a native call) so that the address that you pass to the native function doesn't change.  This is ultimately important if you are getting data back from the native call (for instance reading data from a Socket).

The extra credit:

You unpin as quickly as possible so you reduce the fragmentation that is caused by having these object frozen in a certain place in the managed heap.  Take a look at Problem 2 in High Memory part 5 - Fragmentation

For the next one, I am thinking of making it more challenging.  Maybe starting off troubleshooting a problem and then ask what you would do next to solve it.  Let me know if you like these or have any suggestions on it.

Skip to main content