質問
pin_ptrの動作をC ++ / CLIで直接実現できますか?たとえば、ネイティブアプリの asm
のようなCLRコードを直接記述することは可能ですか?
私がやりたいことの例は、 pin_ptr
のラッパーです( pin_ptr
sの制限のために不可能です)。
class WrappedPtr
{
public:
explicit WrappedPtr(String^ s)
{
pin = PtrToStringChars(s);
// I want to pin s for the lifetime of this object (only used on the stack)
}
};
解決
GCHandle.Alloc を使用します。 GCHandleType.Pinned を使用します。その後、 GCHandle.AddrOfPinnedObject .NETオブジェクトのアドレスを取得します。
所属していません StackOverflow