Tagging/Encoding Pointers

前端 未结 5 663
青春惊慌失措
青春惊慌失措 2021-01-05 19:11

I need a way to tag a pointer as being either part of set x or part of set y (ie: the tag has only 2 \'states\'), I\'m that means one can assume untagged = x and tagged = y.

5条回答
  •  一向
    一向 (楼主)
    2021-01-05 19:36

    There is no safe and portable way to make that sort of thing work. You might be able to find some system-specific bits that are always a known value (say, the most significant n bits), but that's an extremely fragile and dangerous thing to rely on. You can't tell whether a pointer is "marked" or not unless some of the bits in the pointer have known values in the first place.

    A much better way to do this is to store an identifier in the structure the pointer points to.

提交回复
热议问题