G
Guest
I have two questions:
a) From documentation located at
http://msdn.microsoft.com/library/d...vcmxspec/html/vcManagedExtensionsSpec_7_7.asp,
it says, "Pinning a sub-object defined in a managed object has the effect of
pinning the entire object. For example, if any element of an array is pinned,
then the whole array is also pinned. There are no extensions to the language
for declaring a pinned array. To pin an array, declare a pinning pointer to
its element type, and pin one of its elements."
My question is, does this still apply if the array is an array of reference
classes instead of value classes? Seems to me that pinning the array (by
pinning the first element of the array) would pin the array itself, and not
necessarily the actual reference class objects which are located elsewhere in
the managed heap.
b) If my assumption in (a) is correct, that means that it is harder to pin
all of the reference class elements of an array. How would you do this?
With an array of __pin pointers? Should this work?
MyObject __pin *pinners __gc[] = new MyObject*[numObjects];
vector<char*> v;
for (int i = 0; i < numObjects; i++)
{
pinners = new MyObject();
v.push_back(static_cast<char*>(pinners));
}
UnmanagedFunction(v);
a) From documentation located at
http://msdn.microsoft.com/library/d...vcmxspec/html/vcManagedExtensionsSpec_7_7.asp,
it says, "Pinning a sub-object defined in a managed object has the effect of
pinning the entire object. For example, if any element of an array is pinned,
then the whole array is also pinned. There are no extensions to the language
for declaring a pinned array. To pin an array, declare a pinning pointer to
its element type, and pin one of its elements."
My question is, does this still apply if the array is an array of reference
classes instead of value classes? Seems to me that pinning the array (by
pinning the first element of the array) would pin the array itself, and not
necessarily the actual reference class objects which are located elsewhere in
the managed heap.
b) If my assumption in (a) is correct, that means that it is harder to pin
all of the reference class elements of an array. How would you do this?
With an array of __pin pointers? Should this work?
MyObject __pin *pinners __gc[] = new MyObject*[numObjects];
vector<char*> v;
for (int i = 0; i < numObjects; i++)
{
pinners = new MyObject();
v.push_back(static_cast<char*>(pinners));
}
UnmanagedFunction(v);