restrict qualifier on member functions (restrict this pointer)

后端 未结 5 1571
清歌不尽
清歌不尽 2021-01-19 02:13

Note: To clarify, the question is not about the use of the restrict keyword in general, but specifically about applying it to member functions

5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-19 02:23

    I'm afraid that I don't clearly understand why you're talking about this.

    restrict specifies that a pointer is not overlapped with others. So, compilers can assume the memory regions pointed by restrict pointers are not dependent, which allows more aggressive optimizations. __restrict__ would be much more effective when used for other pointer variables than this.

    So, what would be a case where one would actually want to give a member a restrict qualifier and where it makes sense?

    Just recall a representative case of using restrict pointers in memcpy:

    void Foo::MyCompute(__restrict__ char* bufA, __restrict__ char* BufB)
    {
    }
    

提交回复
热议问题