P
Pierre
Hi everyone;
I have a class with several members and I pin the first reference field in a
function;
public ref struct MyClass
{
String str1;
List<MySubClass ^> ^subObjects;
....
};
void ManagedFunc(MyClass ^class)
{
pin_ptr<const wchar_t> s1 = PtrToStringChars(class->str1);
.....
}
Now the first question is; which objects are pinned? MSDN documentation says
"Pinning a sub-object defined in a managed object has the effect of pinning
the entire object." But what does "the entire object" mean? Is it just str1
and MyClass? Or are the subObjects list and the elements contained in it
also pinned? Does the runtime pin each and every object that can be reached
from the parent object?
A second question. Why is it not possible to pin a reference type directly
using pin_ptr? Like;
pin_ptr<MyClass ^> pS = gcnew MyClass();
With GCHandle it's possible to directly pin an object, but as far as I
understand pin_ptr does not allow this semantic.
Regards...
I have a class with several members and I pin the first reference field in a
function;
public ref struct MyClass
{
String str1;
List<MySubClass ^> ^subObjects;
....
};
void ManagedFunc(MyClass ^class)
{
pin_ptr<const wchar_t> s1 = PtrToStringChars(class->str1);
.....
}
Now the first question is; which objects are pinned? MSDN documentation says
"Pinning a sub-object defined in a managed object has the effect of pinning
the entire object." But what does "the entire object" mean? Is it just str1
and MyClass? Or are the subObjects list and the elements contained in it
also pinned? Does the runtime pin each and every object that can be reached
from the parent object?
A second question. Why is it not possible to pin a reference type directly
using pin_ptr? Like;
pin_ptr<MyClass ^> pS = gcnew MyClass();
With GCHandle it's possible to directly pin an object, but as far as I
understand pin_ptr does not allow this semantic.
Regards...