Pinning ref objects

  • Thread starter Thread starter Ioannis Vranos
  • Start date Start date
I

Ioannis Vranos

Can this approach pin a ref object, in this case a System::String? (just
because C++ programmers like low level programming and not a language
that tries to protect us from ourselves).


int main()
{
using namespace System;

String ^s="Hello";

pin_ptr<unsigned char> p= *reinterpret_cast<unsigned char **>(&s);
}
 
Ioannis said:
Can this approach pin a ref object, in this case a System::String? (just
because C++ programmers like low level programming and not a language
that tries to protect us from ourselves).


int main()
{
using namespace System;

String ^s="Hello";

pin_ptr<unsigned char> p= *reinterpret_cast<unsigned char **>(&s);
}


Or perhaps this style:


value class ValueClass
{};

ref class RefClass{};


int main()
{
using namespace System;

RefClass obj;

ValueClass ^h=reinterpret_cast<ValueClass ^>(%obj);

// obj is pinned
pin_ptr<ValueClass> p= &*h;

// Unpin
p=nullptr;
}
 
Back
Top