Tagging/Encoding Pointers

前端 未结 5 635
青春惊慌失措
青春惊慌失措 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:35

    You might have ptr1 ^ magic = ptr2 with ptr1 in set X and ptr2 in set Y (unless you prove otherwise). Since (I guess) you don't have control on the pointers addresses you are given, your technique seems to be inadequate.

    An alternative to Vinay solution is to store the tags as bits of a pre-allocated buffer (specially easy if the size of the list is bounded since you don't have to grow or shrink the buffer). This is a very compact and efficient solution that does not require to modify the pointed data structure.

    Cheers,

    -stan

提交回复
热议问题