Recover containing GC object from managed 'ref' interior pointer

前端 未结 1 1205
南方客
南方客 2021-01-18 19:00

This question is newly relevant in light of the new ref locals and ref return features in the latest versions of C# 7:

相关标签:
1条回答
  • 2021-01-18 19:19

    No, recovery of the containing object from an interior pointer is not possible. During GC, interior pointers are translated into corresponding objects thanks to the so-called brick table and plug trees. Given a specified address, the proper brick table entry is calculated and corresponding plug tree is traversed to find the plug within which that address lives. Finally, that plug is scanned object-by-object to find the one that contains the considered address.

    The point is those trees are built and available only during GC. So, even if such an "interior pointer recovery" API existed, it would have to wait for the GC and could provide an answer only afterwards (which seems very impractical). Other solutions, like linear memory scanning, would obviously possibly introduce tremendous overhead.

    0 讨论(0)
提交回复
热议问题