Tagging/Encoding Pointers

前端 未结 5 658
青春惊慌失措
青春惊慌失措 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-05 19:49

    If performance is not a big issue, two std::set's can be used.

    If it's important to get this information quickly, and it's acceptable to use only 2-byte aligned pointers, the lowest bit can be used to store this information. But having "hacked" pointers may appear to be quite error-prone...

提交回复
热议问题