B
Ben Schwehn
If I pin a member of a garbage collected structure, can I safely assume
that the entire struct is pinned?
I use something like that: (new whidbey syntax, but that shouldn't make
a difference):
[StructLayout(LayoutKind::Sequential)]
public ref struct MyStruct {
Int32 memberA;
Int16 memberB;
Int32 memberC;
}
....
MyStruct^ struct = gcnew MyStruct();
void* pData = somedata_somwhere;
//pData points to a memory location,
//that holds data not only about
//memberA but also memberB and memberC
pin_ptr<int> pMemberA = &struct->membera;
memcpy((void*)pMemberA, pData, sizeofdata);
pMemberA = nullptr;
it works but is it correct?
Would it also be correct if i hadn't specified LayoutKind::Sequential?
Thanks
Ben
that the entire struct is pinned?
I use something like that: (new whidbey syntax, but that shouldn't make
a difference):
[StructLayout(LayoutKind::Sequential)]
public ref struct MyStruct {
Int32 memberA;
Int16 memberB;
Int32 memberC;
}
....
MyStruct^ struct = gcnew MyStruct();
void* pData = somedata_somwhere;
//pData points to a memory location,
//that holds data not only about
//memberA but also memberB and memberC
pin_ptr<int> pMemberA = &struct->membera;
memcpy((void*)pMemberA, pData, sizeofdata);
pMemberA = nullptr;
it works but is it correct?
Would it also be correct if i hadn't specified LayoutKind::Sequential?
Thanks
Ben