Nayana Adassuriya
Nayana Adassuriya

Reputation: 24766

What is the different between __declspec(restrict) and __declspec(noalias)

What is the different between __declspec(restrict) and __declspec(noalias) I have read this page https://msdn.microsoft.com/en-us/library/k649tyc7.aspx. but not clear what it is. Can someone explain what problem solve by these two annotations.

Upvotes: 6

Views: 2923

Answers (1)

jlahd
jlahd

Reputation: 6303

__declspec(restrict) declares that the return value of a function points to memory that is not aliased. That is, the memory returned by the function is guaranteed to not be accessible through any other pointer in the program.

__declspec(noalias) declares that the function does not modify memory outside the first level of indirection from the function's parameters. That is, the parameters are the only reference to the outside world the function has.

Neither of these solves any problem as such - they are just performance hints to the compiler. Normally, the compiler would need to ensure that things like caching intermediate results in registers or reordering code would not be affected by potential aliasing on function calls; these declarations are your guarantees as a programmer that the compiler does not need to worry about this when compiling these specific functions.

Upvotes: 10

Related Questions