- Blocks of managed memory allocated on the managed heap might get relocated due to garbage collection.
- To avoid this blocks of memory are locked using the fixed statement
- The fixed statement is made up of two parts:
- An expression that can be converted to an unmanaged type, and
- The declaration of an unmanaged type variable that's assigned the value of the expression.
- An expression that can be converted to an unmanaged type, and
- The address is locked until the statement or statement block that follows the fixed statement has finished executing.
- The fixed statement can target any managed memory block, including instance or static class fields, but the variable that's the target of the fixed statement must be a value type, an array, or a string. It can also lock multiple memory blocks, if they are of the same type
- Locking the memory degrades the performance. So care must be taken lock it for a short duration
fixed
Subscribe to:
Post Comments
(
Atom
)
0 comments :
Post a Comment