Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

How to: Declare Pinning Pointers and Value Types

A value type can be implicitly boxed. You can then declare a pinning pointer to the value type object itself and use a pin_ptr to the boxed value type.

Example

// pin_ptr_value.cpp
// compile with: /clr
value struct V {
   int i;
};

int main() {
   V ^ v = gcnew V;   // imnplicit boxing
   v->i=8;
   System::Console::WriteLine(v->i);
   pin_ptr<V> mv = &*v;
   mv->i = 7;
   System::Console::WriteLine(v->i);
   System::Console::WriteLine(mv->i);
}

Output

8
7
7

See Also

Reference

pin_ptr

Community Additions

ADD
Show:
© 2015 Microsoft