Quantcast
Channel: Common Language Runtime Internals and Architecture forum
Viewing all articles
Browse latest Browse all 1710

Object^* should I pin_ptr it or not ?

$
0
0

Hi,

I would to know if this code is safe or if I need to pin_ptr my Object^* parameter before using it.

ref struct A {
	System::String ^s;
};

void test2(A ^* po) { 
	(*po)->s = "test2"; // is it safe ? 
}

void test(A ^* po) { 
	pin_ptr<A^> pin_po = po; // this is obviously safe
	(*pin_po)->s = "test"; 
}

int main(array<System::String ^> ^args)
{
	A ^a = gcnew A();
	test(&a);
	test2(&a);
    return 0;
}

I don't know exactly how the garbage collector reads local variables so I am not sure if it understands that Object^* can be readen during collection.

Thank you in advance, 

R.H.



Viewing all articles
Browse latest Browse all 1710

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>